Skip to content

removeEventListener overloads should match the overloads provided for addEventListener #19386

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

Activity

  1. mhegazy commented on Oct 21, 2017

    @mhegazy
    Contributor

    We need to generate signatures for removeEventListenter just like we do for addEventListener.

  2. thebanjomatic commented on Oct 21, 2017

    @thebanjomatic
    Author

    I made a go at fixing this myself here: microsoft/TypeScript-DOM-lib-generator#312

  3. added
    Fixed in TSJS repoFix merged in https://github.com/Microsoft/TSJS-lib-generator, but not ported yet
    FixedA PR has been merged for this issue
    and removed
    Fixed in TSJS repoFix merged in https://github.com/Microsoft/TSJS-lib-generator, but not ported yet
    on Oct 23, 2017
  4. locked and limited conversation to collaborators on Jun 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptFixedA PR has been merged for this issueHelp WantedYou can do this

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions