Skip to content

Commit 09f611b

Browse files
committed
feat(emitter): generalize optional dictionary members to allow explicit undefined
1 parent fad5aab commit 09f611b

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/build/emitter.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,9 +1580,11 @@ export function emitWebIdl(
15801580
.sort(compareName)
15811581
.forEach((m) => {
15821582
emitComments(m, printer.printLine);
1583-
printer.printLine(
1584-
`${m.name}${m.required ? "" : "?"}: ${convertDomTypeToTsType(m)};`,
1585-
);
1583+
let type = convertDomTypeToTsType(m);
1584+
if (!m.required && !type.split(" | ").includes("undefined")) {
1585+
type += " | undefined";
1586+
}
1587+
printer.printLine(`${m.name}${m.required ? "" : "?"}: ${type};`);
15861588
});
15871589
}
15881590
if (dict.overrideIndexSignatures) {

0 commit comments

Comments
 (0)