CustomEvent.detail is null when not defined
CustomEvent.detail is defined as follows:
interface CustomEvent<T = any> extends Event {
readonly detail: T;
// ...
}
Source: https://github.com/microsoft/TypeScript-DOM-lib-generator/blob/957eced9e98fc61bf86ab9524deb5eaa1f4d3c24/inputfiles/overridingTypes.jsonc#L538-L540
This is slightly wrong as CustomEvent.detail defaults to null when not defined: Playground
The playground contains a fix I suggest: detail: T extends {} ? T : null
I'll open a PR referring to this issue
What about this code?
new CustomEvent("myEvent", { detail: false });
Edit: I am surprised but this seems to work with your PR, too.
JFYI: This is easier to debug in playground with instant type highlighting:
let A: RealDetailType<undefined>
// ^?
let B: RealDetailType<void>
// ^?
let C: RealDetailType<null>
// ^?
let D: RealDetailType<string | undefined>
// ^?
let E: RealDetailType<boolean>
// ^?
I didn't know about the ^? trick, thanks @HolgerJeromin!
I'm not sure to understand the problem with detail: false, as false is defined, new CustomEvent("e", { detail: false }).detail === false
I thought false would not qualify T extends {} so the result would be null instead of T. But, yes this worked.
Sorry for the noise :)