Closed
Description
TypeScript Version: 2.6.0-rc
addEventListener has a bunch of handy overloads to map things like: 'touchmove' to (ev: TouchEvent) => any
etc. Unfortunately, the same overloads are not provided for removeEventListener
. Normally that isn't a problem, but with the new strictFunctionTypes option, valid code is now producing errors.
Code
Compiled with: --strictFunctionTypes
function handleTouchMove(event: TouchEvent) {
}
// Works fine because overloads are provided that map 'touchmove' to TouchEvent
window.addEventListener('touchmove', handleTouchMove, true);
// This produces an error
window.removeEventListener('touchmove', handleTouchMove, true);
error:
error TS2345: Argument of type '(ev: TouchEvent) => any' is not assignable to parameter of type 'EventListenerOrEventListenerObject'.
Type '(ev: TouchEvent) => any' is not assignable to type 'EventListenerObject'.
Property 'handleEvent' is missing in type '(ev: TouchEvent) => any'.
You can use the following type assertion to defeat the error, but I don't believe that should be necessary:
window.removeEventListener('touchmove', <(ev: Event) => any>handleTouchMove, true);
Expected behavior:
Compiles without errors
Actual behavior:
Compiles with an error on the second parameter passed to window.removeEventListener
Related: #3871