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: CustomEvent generic type #1759

Merged
merged 1 commit into from
Mar 5, 2024
Merged

Conversation

Cherry
Copy link
Contributor

@Cherry Cherry commented Mar 3, 2024

Fixes #1504

This overrides the CustomEvent types to better match other implementations.

This is my first time contributing to workerd, and really using JSG at all, so apologies if there's anything weird with this change. If there's a better way to do this, please just let me know.

Old output:

export declare class CustomEvent extends Event {
  constructor(type: string, init?: CustomEventCustomEventInit);
  get detail(): any | undefined;
}

New output:

export declare class CustomEvent<T = any> extends Event {
  constructor(type: string, init?: CustomEventCustomEventInit);
  get detail(): T;
}

TypeScript lib.dom.d.ts reference: https://github.com/microsoft/TypeScript/blob/1d6d962d3132a901f5fb48be4a389c45faf5a74e/src/lib/dom.generated.d.ts#L5935

@Cherry Cherry requested review from a team as code owners March 3, 2024 21:36
@Cherry Cherry requested review from byule and Warfields March 3, 2024 21:36
Copy link

github-actions bot commented Mar 3, 2024

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@Cherry
Copy link
Contributor Author

Cherry commented Mar 3, 2024

I have read the CLA Document and I hereby sign the CLA

github-actions bot added a commit that referenced this pull request Mar 3, 2024
@Cherry
Copy link
Contributor Author

Cherry commented Mar 5, 2024

Test failure here looks to be unrelated:

LLVM ERROR: IO failure on output stream: no space on device

@jasnell
Copy link
Member

jasnell commented Mar 5, 2024

Yep, don't worry about that. it's a known issue with the windows-debug job

@jasnell jasnell merged commit 7d5a1d2 into cloudflare:main Mar 5, 2024
10 of 11 checks passed
Comment on lines +221 to +224
JSG_TS_OVERRIDE(<T = any> extends Event {
constructor(type: string, init?: CustomEventCustomEventInit);
get detail(): T;
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for commenting after this was merged, but I think this could be simplified to:

Suggested change
JSG_TS_OVERRIDE(<T = any> extends Event {
constructor(type: string, init?: CustomEventCustomEventInit);
get detail(): T;
});
JSG_TS_OVERRIDE(<T = any> {
get detail(): T;
});

Copy link
Contributor Author

@Cherry Cherry Mar 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can confirm that produces the same types output:

export class CustomEvent<T = any> extends Event {
  constructor(type: string, init?: CustomEventCustomEventInit);
  get detail(): T;
}

Opened a quick PR to improve: #1766

Thanks for catching!

@Cherry Cherry deleted the fix/customevent-types branch March 6, 2024 00:24
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.

CustomEvent is not a generic type
3 participants