Skip to content

unhandledrejection event missing from WindowEventMap #20656

@robatwilliams

Description

@robatwilliams

TypeScript Version: 2.6.1

Code

window.addEventListener('unhandledrejection', event => {
  // event is of type Event
});

window.addEventListener('unhandledrejection', (event: PromiseRejectionEvent) => {
    /*
Argument of type '(event: PromiseRejectionEvent) => void' is not assignable to parameter of type 'EventListenerOrEventListenerObject'.
  Type '(event: PromiseRejectionEvent) => void' is not assignable to type 'EventListenerObject'.
    Property 'handleEvent' is missing in type '(event: PromiseRejectionEvent) => void'.
*/
});

Expected behavior:
Event listener for unhandledrejection should have event type PromiseRejectionEvent.

I believe an entry needs adding to WindowEventMap in lib.dom.d.ts.

Actual behavior:
Compiler error as shown in code sample above, when using strict mode.

Workaround:
Use declaration merging; create a typings file and include

interface WindowEventMap {
  'unhandledrejection': PromiseRejectionEvent;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptFixedA PR has been merged for this issueGood First IssueWell scoped, documented and has the green lightHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions