Skip to content

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

Closed
@weswigham

Description

@weswigham

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).

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions