The situation is somewhat like:
const searchKeyPressHandler = (appDispatch: any, e: any) => {
if (e.keyCode === 27) {
appDispatch({ type: "closeSearch" })
}
}
document.addEventListener("keyup", searchKeyPressHandler); // <-- error on searchKeyPressHandler
return () => document.removeEventListener("keyup", searchKeyPressHandler); // <-- error on searchKeyPressHandler
searchKeyPressHandler return error using typescript and I don't know how I can avoid it.
document.addEventListener("keyup", function (e) { searchKeyPressHandler(appDispatch, e) });
could be a solution for addEventListener
but it is not useful for removeEventListener because the event will be never removed with
return () => document.removeEventListener("keyup", function (e) { searchKeyPressHandler(appDispatch, e) });.
