-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Support async iterable DOM types #29867
Comments
Hi, I just stumbled upon this. I noticed forEach was removed from ReadableStream in src/lib/dom.generated.d.ts in 4e237ed, but async iteration was not added. The ReadableStream in lib/lib.dom.d.ts still has a forEach and no async iteration. Is there anything I can do to help? |
The At the moment,
Not a whole lot. You can try to convince Chromium (#929585), Gecko (#1496770) and/or WebKit (#194379) to implement async iteration on |
I have a current clone, but the last commit to change that file is from Jul 1, 2021 and forEach is still there: https://github.com/microsoft/TypeScript/blob/main/lib/lib.dom.d.ts#L11924
I guess that explains why deno has its own .d.ts :-)
I would be more likely to try to convince "TSC" of the value of having a deno mode :-) Thanks for the explanation, the situation makes a lot more sense now. |
Huh, strange. It looks like TypeScript's |
Yup, this just bit me. Have to do a weird thing like: const stream = response.body as unknown as AsyncIterable<ConcreteType>; Because |
This is now supported in 4 runtimes (Firefox, Node, Deno, and Bun): https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream#browser_compatibility Can we implement this please? |
|
@saschanaz @sandersn
I can't find |
That's added later because of browser support state and should be added in a future TS version. |
@saschanaz as people have mentioned, this has been supported in many runtimes for over a year, so shouldn't we have a way to opt into these type defs already? Adding |
I mean asyncIterable support is already there, what we need is just a new TS release. ReadableStream.from problem is real and it's still Firefox only. Opting in is not available as we don't have conditional types in TS 😞 and declaration merge is also blocked by web-interface-decls-not-being-class-decls 😭. |
As @saschanaz said, it's already in TypeScript Nightly. You can try it in the Playground. |
Okay my apologies, since parts of this had been done over a year ago I assumed it was being delayed past the next planned release to wait for more environments to catch up, glad to see it will be released soon. |
Search Terms
asynciterator asynciterable async iterable iterator
Suggestion
Add a
dom.asynciterable
option to--lib
to support DOM types that define aSymbol.asyncIterator
method.Use Cases
The streams spec has recently been updated to add a
Symbol.asyncIterator
method toReadableStream
, making it the first DOM type to implement the ES2018AsyncIterable
interface.I would like to update the type definitions for streams in TSJS-lib-generator to include this new async iterator method. However, this requires
Symbol.asyncIterator
, which is not available before ES2018 and thus cannot be readily used in the DOM type definitions.Previously, a
dom.iterable
option was added to support DOM types that define aSymbol.iterator
method. I think it would make sense to use this same strategy to supportSymbol.asyncIterator
.Examples
TypeScript would have (generated) type definitions in
lib/lib.dom.asynciterable.d.ts
:Users could then use a
ReadableStream
in afor await..of
loop by compiling with--target es2018
:Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: