onerror for Elements is incorrect
const img = document.createElement('img')
// type error:
img.onerror = (e: Event) => e
Only Window.onerror should have the alternative signature, but not elements. See:
- https://developer.mozilla.org/en-US/docs/Web/API/Window/error_event
- https://udn.realityripple.com/docs/Web/API/GlobalEventHandlers/onerror
The situation I ran into is that trying to create JSX types for Custom Elements, it is leaking into the JSX types, causing unexpected errors:
| string fixes the error, but is not accurate:
To work around the issue in JSX types, we can override it like so (differs slightly depending on the JSX from Solid, Preact, React, etc):
interface IntrinsicElements {
'some-element': Omit<JSX.HTMLAttributes<SomeElement>, 'onerror'>
& { onerror?: ((error: ErrorEvent) => void) | null }
& Partial<Pick<SomeElement, 'foo', 'bar'>>
}
This is a bit awkward situation as img inherits from GlobalEventHandlers. I wonder we can somehow override it?
@saschanaz I ran this code,
const img = document.createElement('img')
img.onerror = (...args) => console.log(args.length, ...args)
img.src = '@#$%'
and it logs an 1, Event (not 1, ErrorEvent) in Chrome, Edge, and Firefox, and Safari.
Hmm, maybe the parameter type needs to be just Event, but it still doesn't need the signature of GlobalEventHandlers.onerror.