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

CustomEvent.detail is null when not defined #1585

Open
GauBen opened this issue Jun 29, 2023 · 3 comments · May be fixed by #1586
Open

CustomEvent.detail is null when not defined #1585

GauBen opened this issue Jun 29, 2023 · 3 comments · May be fixed by #1586

Comments

@GauBen
Copy link

GauBen commented Jun 29, 2023

CustomEvent.detail is defined as follows:

interface CustomEvent<T = any> extends Event {
    readonly detail: T;

	// ...
}

Source:

"detail": {
"overrideType": "T"
}

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

@HolgerJeromin
Copy link

HolgerJeromin commented Jun 29, 2023

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> 
//  ^?

@GauBen
Copy link
Author

GauBen commented Jun 29, 2023

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

@HolgerJeromin
Copy link

HolgerJeromin commented Jun 29, 2023

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 :)

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 a pull request may close this issue.

2 participants