0

我正在使用文档中的示例

const keyMap = {
    CONTRACT: "alt+down",
    COMMAND_DOWN: { sequence: "command", action: "keydown" }
};

我收到这个错误。

No overload matches this call.
  Overload 1 of 2, '(props: Readonly<GlobalHotKeysProps>): GlobalHotKeys', gave the following error.
    Type '{ CONTRACT: string; COMMAND_DOWN: { sequence: string; action: string; }; }' is not assignable to type 'KeyMap'.
      Property 'COMMAND_DOWN' is incompatible with index signature.
        Type '{ sequence: string; action: string; }' is not assignable to type 'KeySequence'.
          Property 'sequences' is missing in type '{ sequence: string; action: string; }' but required in type 'ExtendedKeyMapOptions'.
  Overload 2 of 2, '(props: GlobalHotKeysProps, context?: any): GlobalHotKeys', gave the following error.
    Type '{ CONTRACT: string; COMMAND_DOWN: { sequence: string; action: string; }; }' is not assignable to type 'KeyMap'.  TS2769

反应热键:https ://github.com/greena13/react-hotkeys

4

1 回答 1

0

您必须将 keyMap 的数据类型指定为 KeyMap。

import { KeyMap } from 'react-hotkeys';

const keyMap: KeyMap = {
    CONTRACT: "alt+down",
    COMMAND_DOWN: { sequence: "command", action: "keydown" }
};
于 2020-07-31T05:02:41.997 回答