Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The new EventListener definition is not backwards compatible and/or has an error #21948

Closed
weswigham opened this issue Feb 14, 2018 · 2 comments
Assignees
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Fixed A PR has been merged for this issue

Comments

@weswigham
Copy link
Member

TypeScript Version: 2.7.0-dev.201xxxxx

I think was broken by #21889, and is not one of the changes listed as a fixed bug in the PR, so may be unintentional. The change has consequently has broken a handful of our RWC tests. Specifically, very common patterns like

Code

this._pseudoStatesToggle.addEventListener("DOMAttrModified", (mutationEvent: MutationEvent): boolean => {
                                                                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '(mutationEvent: MutationEvent) => boolean' is not assignable to parameter of type 'EventListener'.
!!! error TS2345:   Type 'boolean' is not assignable to type 'void | { handleEvent(evt: Event): void; }'.    
                    return true;
                });

The change is that the webworker lib file now defines EventListener as:

type EventListener = (evt: Event) => void | { handleEvent(evt: Event): void; };

but it was:

interface EventListener {
    (evt: Event): void;
}

There also used to be a type:

declare type EventListenerOrEventListenerObject = EventListener | EventListenerObject;

that some RWC tests rely on (and this type looks to be what the alias is emulating).

@falsandtru
Copy link
Contributor

falsandtru commented Feb 14, 2018

microsoft/TypeScript-DOM-lib-generator#352 breaks the acceptability (type safety) of interfaces depended on EventListener type. This is a large breaking change. This change should be reverted.

@weswigham weswigham changed the title The new EventListener definition is not backwards compatible The new EventListener definition is not backwards compatible or has an error Feb 14, 2018
@weswigham
Copy link
Member Author

weswigham commented Feb 14, 2018

EventListenerOrEventListenerObject is also relied upon by some real code bases (even if it should just be an alias for EventListener now).
Also,

type EventListener = (evt: Event) => void | { handleEvent(evt: Event): void; };

is probably just straight wrong, even by original intent, since that is parsed as "A function with an argument of type Event and a return type of either (void OR an object with a handleEvent method)" and not "(A function that returns void with an argument of type Event) OR (an object with a handleEvent method)."

@weswigham weswigham changed the title The new EventListener definition is not backwards compatible or has an error The new EventListener definition is not backwards compatible and/or has an error Feb 14, 2018
@DanielRosenwasser DanielRosenwasser added Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript labels Feb 15, 2018
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 2.7.3 milestone Feb 15, 2018
mhegazy added a commit to microsoft/TypeScript-DOM-lib-generator that referenced this issue Feb 15, 2018
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Feb 16, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

4 participants