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

Make Keyhandler hotkeysEvent parameter optional #297

Closed
wants to merge 1 commit into from

Conversation

julianrubisch
Copy link

From the docs I take that actually both of the arguments passed to the handler are optional, but to get this library to work properly with other libraries/applications written in TypeScript it would be preferable to actually make this second event parameter optional.

Please close at will if I'm wrong!

@jaywcjlove
Copy link
Owner

@julianrubisch The second parameter must be there

@jaywcjlove jaywcjlove closed this Jun 10, 2021
@julianrubisch julianrubisch deleted the patch-1 branch June 10, 2021 14:13
@julianrubisch
Copy link
Author

So if I use it with JavaScript it's optional but when using with TypeScript not?

@jaywcjlove
Copy link
Owner

@julianrubisch I do not understand. It can be used on typescript.

@julianrubisch
Copy link
Author

My question is: in all the examples in the docs the parameters appear to be optional, and that's also how they appear to be widely used. In my own code, I sometimes use no event parameter at all when defining the handler

However if I use typescript I have to do weird type coercions when no second parameter is used.

But I'm not too Typescript savvy so I'm probably all wrong 🤷‍♂️

@jaywcjlove
Copy link
Owner

@julianrubisch

hotkeys('ctrl+a,ctrl+b,r,f', function (event, handler){
 // No need to judge the existence of `handler`
 handleFunction(event)
});

// `handler` optional
function handleFunction(event: KeyboardEvent) {
}
hotkeys('ctrl+a,ctrl+b,r,f', handleFunction);
// `handler` required
function handleFunction(event: KeyboardEvent, handler: HotkeysEvent) {
}

@julianrubisch
Copy link
Author

Thanks!

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