Skip to content
2 changes: 2 additions & 0 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ async function emitDom() {
allowUnrelatedSetterType: true,
useGenericTypedArrays: true,
includeIterable: true,
treatAsyncSequence: true,
},
},
// ts5.7 (and later)
Expand All @@ -262,6 +263,7 @@ async function emitDom() {
useIteratorObject: true,
allowUnrelatedSetterType: true,
useGenericTypedArrays: true,
treatAsyncSequence: true,
},
},
// ts5.6
Expand Down
13 changes: 13 additions & 0 deletions src/build/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ export interface CompilerBehavior {
allowUnrelatedSetterType?: boolean;
useGenericTypedArrays?: boolean;
includeIterable?: boolean;
/** If true, treat async_sequence as AsyncIterable<T>, otherwise as any (legacy < TS 4.4 emit). */
treatAsyncSequence?: boolean;
}

export function emitWebIdl(
Expand Down Expand Up @@ -405,6 +407,17 @@ export function emitWebIdl(
forReturn: boolean,
): string {
function convertBaseType() {
// Support async_sequence (see https://github.com/whatwg/streams/pull/1372)
if (obj.type === "async_sequence") {
// AsyncIterable<T> requires separate asynciterable.d.ts until TS 6.0.
// To make it correct, we need to defer any functions using async_sequence to the asynciterable variant.
// For now, skip generation and warn.
console.warn(
"Skipping generation for a function or property with async_sequence type: " +
JSON.stringify(obj),
);
return "never"; // Use 'never' to signal omission in type generation
}
if (obj.type === "sequence" && !forReturn && iterator !== "") {
return "Iterable";
}
Expand Down