Skip to content

GlobalEventHandlers.onerror should be of type ErrorEventHandler | null #29876

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

Closed
thdk opened this issue Feb 12, 2019 · 3 comments
Closed

GlobalEventHandlers.onerror should be of type ErrorEventHandler | null #29876

thdk opened this issue Feb 12, 2019 · 3 comments
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Help Wanted You can do this
Milestone

Comments

@thdk
Copy link

thdk commented Feb 12, 2019

TypeScript Version: 3.2.1

Search Terms: lib.dom.ts GlobalEventHandlers onerror

Code

const imageEl = document.createElement("img");

// enable strictNullChecks in options and below line will give a type error
// type 'null' is not assignable to type 'ErrorEventHandler'
imageEl.onerror = null;

Expected behavior:
it should be possible to assign null to onerror

Actual behavior:
type 'null' is not assignable to type 'ErrorEventHandler'

Playground Link:
Playground link

Related Issues:
#28638 (not really related)


I believe line https://github.com/Microsoft/TypeScript/blob/master/lib/lib.dom.d.ts#L5478 can be modified to allow null as follows:
Option 1:

/**
     * Fires when an error occurs during object loading.
     * @param ev The event.
     */
    onerror: ErrorEventHandler | null;

Option 2

interface ErrorEventHandlerNonNull {
    (event: Event | string, source?: string, fileno?: number, columnNumber?: number, error?: Error): void;
}

and a type ErrorEventHandler

type ErrorEventHandler = ErrorEventHandlerNonNull | null;

and leave 'onerror: ErrorEventHandler;' as is.

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Help Wanted You can do this labels Feb 19, 2019
@RyanCavanaugh RyanCavanaugh added this to the Community milestone Feb 19, 2019
@RyanCavanaugh RyanCavanaugh modified the milestones: Community, Backlog Mar 7, 2019
@Fabianopb
Copy link

I've some spare time these weeks, I could take a look at this one too!

@Fabianopb
Copy link

Fabianopb commented Mar 11, 2019

I've checked the issue, apparently this is already implemented in the latest version (3.3.3333) using your Option2.

@thdk could you please check the following references and confirm that?

https://github.com/Microsoft/TypeScript/blob/v3.3.3333/lib/lib.dom.d.ts#L17115
https://github.com/Microsoft/TypeScript/blob/v3.3.3333/lib/lib.dom.d.ts#L17827

If that's true than @RyanCavanaugh can close the issue.

@thdk
Copy link
Author

thdk commented Mar 12, 2019

@Fabianopb seems to fixed indeed in 3.3.3333 👍

I'll close the issue.

@thdk thdk closed this as completed Mar 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

3 participants