@@ -289,6 +289,17 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor, iterator: boo
289
289
return type . nullable ? makeNullable ( type . name ) : type . name ;
290
290
}
291
291
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
+
292
303
function convertDomTypeToTsTypeWorker ( obj : Browser . Typed ) : { name : string ; nullable : boolean } {
293
304
let type ;
294
305
if ( typeof obj . type === "string" ) {
@@ -542,7 +553,7 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor, iterator: boo
542
553
const m = methods [ 0 ] ;
543
554
const overload = m . signature [ 0 ] ;
544
555
const paramsString = overload . param ? paramsToString ( overload . param ) : "" ;
545
- const returnType = overload . type ? convertDomTypeToTsType ( overload ) : "void" ;
556
+ const returnType = overload . type ? convertDomTypeToTsReturnType ( overload ) : "void" ;
546
557
printer . printLine ( `type ${ i . name } = ((${ paramsString } ) => ${ returnType } ) | { ${ m . name } (${ paramsString } ): ${ returnType } ; };` ) ;
547
558
}
548
559
printer . printLine ( "" ) ;
@@ -690,7 +701,7 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor, iterator: boo
690
701
691
702
function emitSignature ( s : Browser . Signature , prefix : string | undefined , name : string | undefined , printLine : ( s : string ) => void ) {
692
703
const paramsString = s . param ? paramsToString ( s . param ) : "" ;
693
- let returnType = convertDomTypeToTsType ( s ) ;
704
+ let returnType = convertDomTypeToTsReturnType ( s ) ;
694
705
returnType = s . nullable ? makeNullable ( returnType ) : returnType ;
695
706
emitComments ( s , printLine ) ;
696
707
printLine ( `${ prefix || "" } ${ name || "" } (${ paramsString } ): ${ returnType } ;` ) ;
0 commit comments