Search Terms
asynciterator asynciterable async iterable iterator
Suggestion
Add a dom.asynciterable option to --lib to support DOM types that define a Symbol.asyncIterator method.
Use Cases
The streams spec has recently been updated to add a Symbol.asyncIterator method to ReadableStream, making it the first DOM type to implement the ES2018 AsyncIterable 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 a Symbol.iterator method. I think it would make sense to use this same strategy to support Symbol.asyncIterator.
Examples
TypeScript would have (generated) type definitions in lib/lib.dom.asynciterable.d.ts:
interface ReadableStream<R = any> {
[Symbol.asyncIterator](): AsyncIterator<R>;
}
Users could then use a ReadableStream in a for await..of loop by compiling with --target es2018:
const readable = new ReadableStream<Uint8Array>();
for await (const chunk of readable) {
console.log(chunk);
}
Checklist
My suggestion meets these guidelines:
Search Terms
asynciterator asynciterable async iterable iterator
Suggestion
Add a
dom.asynciterableoption to--libto support DOM types that define aSymbol.asyncIteratormethod.Use Cases
The streams spec has recently been updated to add a
Symbol.asyncIteratormethod toReadableStream, making it the first DOM type to implement the ES2018AsyncIterableinterface.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.iterableoption was added to support DOM types that define aSymbol.iteratormethod. 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
ReadableStreamin afor await..ofloop by compiling with--target es2018:Checklist
My suggestion meets these guidelines: