Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
16 changes: 16 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 Expand Up @@ -442,6 +455,9 @@ export function emitWebIdl(
}

const type = convertBaseType();
if (type === "any") {
return type;
}
let subtypeString = arrayify(obj.subtype)
.map((t) => convertDomTypeToTsTypeBase(t, forReturn))
.join(", ");
Expand Down
Loading