Skip to content

chore: override OnErrorEventHandlerNonNull #1950

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions baselines/dom.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11658,6 +11658,7 @@ interface HTMLImageElement extends HTMLElement {
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLImageElement/naturalWidth)
*/
readonly naturalWidth: number;
onerror: (event: Event) => void;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLImageElement/referrerPolicy) */
referrerPolicy: string;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLImageElement/sizes) */
Expand Down
1 change: 1 addition & 0 deletions baselines/ts5.5/dom.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11644,6 +11644,7 @@ interface HTMLImageElement extends HTMLElement {
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLImageElement/naturalWidth)
*/
readonly naturalWidth: number;
onerror: (event: Event) => void;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLImageElement/referrerPolicy) */
referrerPolicy: string;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLImageElement/sizes) */
Expand Down
4 changes: 4 additions & 0 deletions inputfiles/addedTypes.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,10 @@
},
"loading": {
"overrideType": "\"eager\" | \"lazy\""
},
"onerror": {
"name": "onerror",
"overrideType": "(event: Event) => void"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would only solve HTMLImageElement, maybe it should go to HTMLElement to solve it for other HTML elements.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the CI fails: Error: generated/dom.generated.d.ts(11577,11): error TS2430: Interface 'HTMLImageElement' incorrectly extends interface 'HTMLElement'.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @saschanaz,

I have applied the changes to all elements.

I was facing a build error due to the lack of documentation on the JSON format. However, replacing GlobalEventHandlers with Omit<GlobalEventHandlers, 'onerror'> solves the issue.

Maybe we could start documenting the format to help others in the future?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Omit sounds ok, but maybe you didn't push your change?

Documentations sounds nice. I wonder we can have a local schema file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just adding some comments to existing type declarations would be okay.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @saschanaz
My question is how to override the type?
I have tried to add it to the overriding types but it didn't work.

}
}
}
Expand Down
8 changes: 8 additions & 0 deletions unittests/files/onerror.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable no-var */
// this should not show error
window.onerror = (_message, _source, _lineno, _colno, _error) => {};

// this also should not show error
declare var img: HTMLImageElement;
img.onerror = (_event: Event) => {};
Loading