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

fix: updated CustomEvent.detail to be null when not defined #1586

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion baselines/audioworklet.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ interface CustomEvent<T = any> extends Event {
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/CustomEvent/detail)
*/
readonly detail: T;
readonly detail: T extends {} ? T : null;
/**
* @deprecated
*
Expand Down
2 changes: 1 addition & 1 deletion baselines/dom.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5892,7 +5892,7 @@ interface CustomEvent<T = any> extends Event {
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/CustomEvent/detail)
*/
readonly detail: T;
readonly detail: T extends {} ? T : null;
/**
* @deprecated
*
Expand Down
2 changes: 1 addition & 1 deletion baselines/serviceworker.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1710,7 +1710,7 @@ interface CustomEvent<T = any> extends Event {
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/CustomEvent/detail)
*/
readonly detail: T;
readonly detail: T extends {} ? T : null;
/**
* @deprecated
*
Expand Down
2 changes: 1 addition & 1 deletion baselines/sharedworker.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1637,7 +1637,7 @@ interface CustomEvent<T = any> extends Event {
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/CustomEvent/detail)
*/
readonly detail: T;
readonly detail: T extends {} ? T : null;
/**
* @deprecated
*
Expand Down
2 changes: 1 addition & 1 deletion baselines/webworker.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1846,7 +1846,7 @@ interface CustomEvent<T = any> extends Event {
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/CustomEvent/detail)
*/
readonly detail: T;
readonly detail: T extends {} ? T : null;
/**
* @deprecated
*
Expand Down
2 changes: 1 addition & 1 deletion inputfiles/overridingTypes.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@
"properties": {
"property": {
"detail": {
"overrideType": "T"
"overrideType": "T extends {} ? T : null"
}
}
},
Expand Down
16 changes: 16 additions & 0 deletions unittests/files/customevents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
new CustomEvent<null>("a").detail satisfies null;
new CustomEvent<void>("b").detail satisfies null;
new CustomEvent<undefined>("c").detail satisfies null;
new CustomEvent<string>("d").detail satisfies string;
new CustomEvent<string | undefined>("e").detail satisfies string | null;

// @ts-expect-error Wrong type
new CustomEvent<null>("a").detail satisfies undefined;
// @ts-expect-error Wrong type
new CustomEvent<void>("b").detail satisfies void;
// @ts-expect-error Wrong type
new CustomEvent<undefined>("c").detail satisfies undefined;
// @ts-expect-error Wrong type
new CustomEvent<string>("d").detail satisfies number;
// @ts-expect-error Wrong type
new CustomEvent<string | undefined>("e").detail satisfies string | undefined;
22 changes: 15 additions & 7 deletions unittests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,24 @@ import { readdir } from "fs/promises";

for (const filename of await readdir(new URL("files/", import.meta.url))) {
if (filename.endsWith(".ts")) {
execSync(`npx tsc generated/dom.generated.d.ts unittests/files/${filename} --target es2020 --lib es2020 --types --noEmit`, {
stdio: "inherit"
});
execSync(
`npx tsc generated/dom.generated.d.ts unittests/files/${filename} --strict --strictNullChecks --target es2020 --lib es2020 --types --noEmit`,
{
stdio: "inherit",
}
);
}
}

for (const filename of await readdir(new URL("files/audioworklet", import.meta.url))) {
for (const filename of await readdir(
new URL("files/audioworklet", import.meta.url)
)) {
if (filename.endsWith(".ts")) {
execSync(`npx tsc generated/audioworklet.generated.d.ts unittests/files/audioworklet/${filename} --target es2020 --lib es2020 --types --noEmit`, {
stdio: "inherit"
});
execSync(
`npx tsc generated/audioworklet.generated.d.ts unittests/files/audioworklet/${filename} --strict --strictNullChecks --target es2020 --lib es2020 --types --noEmit`,
{
stdio: "inherit",
}
);
}
}