jaywcjlove / hotkeys-js

➷ A robust Javascript library for capturing keyboard input. It has no dependencies.
https://jaywcjlove.github.io/hotkeys-js
MIT License
6.66k stars 410 forks source link

Make Keyhandler hotkeysEvent parameter optional #297

Closed julianrubisch closed 3 years ago

julianrubisch commented 3 years ago

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 commented 3 years ago

@julianrubisch The second parameter must be there

julianrubisch commented 3 years ago

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

jaywcjlove commented 3 years ago

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

julianrubisch commented 3 years ago

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 commented 3 years ago

@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 commented 3 years ago

Thanks!