@@ -51,19 +51,18 @@ export class ExpansionConfig {
51
51
* @return a new model with generics expanded
52
52
*/
53
53
export function expandGenerics ( inputModel : Model , config ?: ExpansionConfig ) : Model {
54
-
55
54
const typesToUnwrap = new Set < string > ( )
56
55
const typesToInline : Set < string > = new Set < string > ( )
57
56
58
- for ( const name of config ?. unwrappedTypes || [ ] ) {
57
+ for ( const name of config ?. unwrappedTypes ?? [ ] ) {
59
58
if ( typeof name === 'string' ) {
60
59
typesToUnwrap . add ( name )
61
60
} else {
62
61
typesToUnwrap . add ( nameKey ( name ) )
63
62
}
64
63
}
65
64
66
- for ( const name of config ?. inlinedTypes || [ ] ) {
65
+ for ( const name of config ?. inlinedTypes ?? [ ] ) {
67
66
if ( typeof name === 'string' ) {
68
67
typesToInline . add ( name )
69
68
} else {
@@ -336,28 +335,29 @@ export function expandGenerics (inputModel: Model, config?: ExpansionConfig): Mo
336
335
337
336
// If this is a type that has to be unwrapped, return its generic parameter's type
338
337
if ( typesToUnwrap . has ( valueOfType ) ) {
339
- // @ts -ignore
340
- return expandValueOf ( value . generics [ 0 ] , mappings )
338
+ // @ts -expect-error
339
+ const x = value . generics [ 0 ]
340
+ return expandValueOf ( x , mappings )
341
341
}
342
342
343
343
// If this is a type that has to be inlined
344
344
if ( typesToInline . has ( valueOfType ) ) {
345
345
// It has to be an alias (e.g. Stringified or WithNullValue
346
346
const inlinedTypeDef = inputTypeByName . get ( valueOfType )
347
- if ( ! inlinedTypeDef || inlinedTypeDef . kind !== 'type_alias' ) {
347
+ if ( inlinedTypeDef ? .kind !== 'type_alias' ) {
348
348
throw Error ( `Inlined type ${ valueOfType } should be an alias definition` )
349
349
}
350
350
351
351
const inlineMappings = new Map < string , ValueOf > ( )
352
- for ( let i = 0 ; i < ( inlinedTypeDef . generics ?. length || 0 ) ; i ++ ) {
353
- // @ts -ignore
352
+ for ( let i = 0 ; i < ( inlinedTypeDef . generics ?. length ?? 0 ) ; i ++ ) {
353
+ // @ts -expect-error
354
354
const source = inlinedTypeDef . generics [ i ]
355
- // @ts -ignore
356
- const dest = value . generics [ i ] ;
355
+ // @ts -expect-error
356
+ const dest = value . generics [ i ]
357
357
inlineMappings . set ( nameKey ( source ) , dest )
358
358
}
359
359
360
- return expandValueOf ( inlinedTypeDef . type , inlineMappings ) ;
360
+ return expandValueOf ( inlinedTypeDef . type , inlineMappings )
361
361
}
362
362
363
363
// If this is a generic parameter, return its mapping
@@ -486,7 +486,7 @@ async function expandGenericsFromFile (inPath: string, outPath: string): Promise
486
486
const inputModel = JSON . parse ( inputText )
487
487
const outputModel = expandGenerics ( inputModel , {
488
488
// unwrappedTypes: ["_spec_utils:Stringified"],
489
- inlinedTypes : [ " _spec_utils:WithNullValue" ]
489
+ inlinedTypes : [ ' _spec_utils:WithNullValue' ]
490
490
} )
491
491
492
492
await writeFile (
0 commit comments