Closed julianrubisch closed 3 years ago
@julianrubisch The second parameter must be there
So if I use it with JavaScript it's optional but when using with TypeScript not?
@julianrubisch I do not understand. It can be used on typescript.
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 🤷♂️
@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) {
}
Thanks!
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!