Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] ExtendedKeyMapOptions extends KeyMapOptions #287

Open
EasierLikeThis opened this issue Aug 7, 2020 · 0 comments
Open

[BUG] ExtendedKeyMapOptions extends KeyMapOptions #287

EasierLikeThis opened this issue Aug 7, 2020 · 0 comments

Comments

@EasierLikeThis
Copy link

Describe the bug
The KeySequence type is defined in such a way that it's difficult to define an object of type ExtendedKeyMapOptions without the use of the as keyword. For example:

export const globalKeyMap = {
  ZOOM_IN_OUT: {
    name: "Zoom video in / out",
    sequences: ["shift+=", "shift+-"]
  },
};

will result in the following:

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

I believe removing the extends from ExtendedKeyMapOptions would provide the desired type structure needed.

How are you using react hotkeys components? (HotKeys, GlobalHotKeys, IgnoreKeys etc)
Both HotKeys and GlobalHotKeys (but I believe this issue is present when defining any KeyMap).

Expected behavior
I should be able to define my KeySequence object without the need to cast or use the as keyword.

Platform (please complete the following information):

  • Version of react-hotkeys: ^2.0.0
  • Browser [e.g. chrome, safari]: N/A
  • OS: [e.g. iOS]: N/A

Are you willing and able to create a PR request to fix this issue?
Yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant