@@ -289,14 +289,25 @@ 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" ) {
295
306
type = { name : convertDomTypeToTsTypeSimple ( obj . type ) , nullable : ! ! obj . nullable } ;
296
307
}
297
308
else {
298
309
const types = obj . type . map ( convertDomTypeToTsTypeWorker ) ;
299
- const isAny = types . find ( t => t . name === "any" ) ;
310
+ const isAny = types . some ( t => t . name === "any" ) ;
300
311
if ( isAny ) {
301
312
type = {
302
313
name : "any" ,
@@ -306,7 +317,7 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor, iterator: boo
306
317
else {
307
318
type = {
308
319
name : types . map ( t => t . name ) . join ( " | " ) ,
309
- nullable : ! ! types . find ( t => t . nullable ) || ! ! obj . nullable
320
+ nullable : types . some ( t => t . nullable ) || ! ! obj . nullable
310
321
} ;
311
322
}
312
323
}
@@ -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 ( "" ) ;
@@ -590,9 +601,9 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor, iterator: boo
590
601
function isCovariantEventHandler ( i : Browser . Interface , p : Browser . Property ) {
591
602
return isEventHandler ( p ) &&
592
603
iNameToEhParents [ i . name ] && iNameToEhParents [ i . name ] . length > 0 &&
593
- ! ! iNameToEhParents [ i . name ] . find (
604
+ iNameToEhParents [ i . name ] . some (
594
605
i => iNameToEhList [ i . name ] && iNameToEhList [ i . name ] . length > 0 &&
595
- ! ! iNameToEhList [ i . name ] . find ( e => e . name === p . name ) ) ;
606
+ iNameToEhList [ i . name ] . some ( e => e . name === p . name ) ) ;
596
607
}
597
608
598
609
function emitProperty ( prefix : string , i : Browser . Interface , emitScope : EmitScope , p : Browser . Property ) {
@@ -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 } ;` ) ;
@@ -990,8 +1001,8 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor, iterator: boo
990
1001
// Some types are static types with non-static members. For example,
991
1002
// NodeFilter is a static method itself, however it has an "acceptNode" method
992
1003
// that expects the user to implement.
993
- const hasNonStaticMethod = i . methods && ! ! mapToArray ( i . methods . method ) . find ( m => ! m . static ) ;
994
- const hasProperty = i . properties && mapToArray ( i . properties . property ) . find ( p => ! p . static ) ;
1004
+ const hasNonStaticMethod = i . methods && mapToArray ( i . methods . method ) . some ( m => ! m . static ) ;
1005
+ const hasProperty = i . properties && mapToArray ( i . properties . property ) . some ( p => ! p . static ) ;
995
1006
const hasNonStaticMember = hasNonStaticMethod || hasProperty ;
996
1007
997
1008
// For static types with non-static members, we put the non-static members into an
0 commit comments