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

Improve type of WritableStreamDefaultController.signal #157

Merged
merged 7 commits into from
Jan 5, 2025

Conversation

MattiasBuelens
Copy link
Owner

Previously, we defined our own AbortSignal type, which was a small subset of the one defined in TypeScript's DOM types and @types/node. However, this prevents users from using the full AbortSignal API, for example passing { once: true } to signal.addEventListener().

Recently, I came across a neat trick in @types/node to query the existence of a globally defined type:

var AbortSignal: typeof globalThis extends { onmessage: any; AbortSignal: infer T } ? T : /* fallback */;

I'm now using the same trick to get the exact AbortSignal type, while still allowing users to use either lib.dom.d.ts or @types/node in their project. 😁

@MattiasBuelens MattiasBuelens added this to the 4.1.0 milestone Jan 5, 2025
@MattiasBuelens MattiasBuelens force-pushed the improve-abortsignal-type branch 2 times, most recently from b6c113a to ded8156 Compare January 5, 2025 20:33
@MattiasBuelens MattiasBuelens force-pushed the improve-abortsignal-type branch from ded8156 to 82f3bb2 Compare January 5, 2025 20:34
@MattiasBuelens MattiasBuelens merged commit 05e8383 into master Jan 5, 2025
5 checks passed
@MattiasBuelens MattiasBuelens deleted the improve-abortsignal-type branch January 5, 2025 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant