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

chore: override OnErrorEventHandlerNonNull #1950

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

Bashamega
Copy link
Contributor

fixes #1821

@Bashamega Bashamega marked this pull request as ready for review March 28, 2025 05:00
Copy link
Contributor

Thanks for the PR!

This section of the codebase is owned by @saschanaz - if they write a comment saying "LGTM" then it will be merged.

@saschanaz
Copy link
Contributor

This would break window.onerror as it does receive a string. We should probably limit this string use case to window and not expose it to other interfaces. Perhaps we can modify GlobalEventHandlers.onerror with the general (error: Error) and add the current onerror to WindowEventHandlers? But would that cause collision?

@Bashamega
Copy link
Contributor Author

This would break window.onerror as it does receive a string. We should probably limit this string use case to window and not expose it to other interfaces. Perhaps we can modify GlobalEventHandlers.onerror with the general (error: Error) and add the current onerror to WindowEventHandlers? But would that cause collision?

Okay

@Bashamega
Copy link
Contributor Author

Hello @saschanaz
Is this better?

@saschanaz
Copy link
Contributor

Hmm. Maybe we should first make some unit tests in https://github.com/microsoft/TypeScript-DOM-lib-generator/tree/main/unittests/files, something like:

// onerror.ts

// this should not show error
window.onerror = (message: string, source: string, lineno: number, colno: number, error: any) => {};

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

The goal here would be to make both pass.

@Bashamega
Copy link
Contributor Author

I have found some issues that i will fix

},
"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.

@Bashamega
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

onerror for Elements is incorrect
2 participants