Skip to content

Commit 255b759

Browse files
Replace "undefined" with "void" in return type
1 parent b0e292f commit 255b759

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/emitter.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,17 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor, iterator: boo
289289
return type.nullable ? makeNullable(type.name) : type.name;
290290
}
291291

292+
function convertDomTypeToTsReturnType(obj: Browser.Typed): string {
293+
const type = convertDomTypeToTsType(obj);
294+
if (type === "undefined") {
295+
return "void";
296+
}
297+
if (type === "Promise<undefined>") {
298+
return "Promise<void>";
299+
}
300+
return type;
301+
}
302+
292303
function convertDomTypeToTsTypeWorker(obj: Browser.Typed): { name: string; nullable: boolean } {
293304
let type;
294305
if (typeof obj.type === "string") {
@@ -542,7 +553,7 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor, iterator: boo
542553
const m = methods[0];
543554
const overload = m.signature[0];
544555
const paramsString = overload.param ? paramsToString(overload.param) : "";
545-
const returnType = overload.type ? convertDomTypeToTsType(overload) : "void";
556+
const returnType = overload.type ? convertDomTypeToTsReturnType(overload) : "void";
546557
printer.printLine(`type ${i.name} = ((${paramsString}) => ${returnType}) | { ${m.name}(${paramsString}): ${returnType}; };`);
547558
}
548559
printer.printLine("");
@@ -690,7 +701,7 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor, iterator: boo
690701

691702
function emitSignature(s: Browser.Signature, prefix: string | undefined, name: string | undefined, printLine: (s: string) => void) {
692703
const paramsString = s.param ? paramsToString(s.param) : "";
693-
let returnType = convertDomTypeToTsType(s);
704+
let returnType = convertDomTypeToTsReturnType(s);
694705
returnType = s.nullable ? makeNullable(returnType) : returnType;
695706
emitComments(s, printLine);
696707
printLine(`${prefix || ""}${name || ""}(${paramsString}): ${returnType};`);

0 commit comments

Comments
 (0)