From d90fc0796f68fac371eeb5609629747ff26d6cb0 Mon Sep 17 00:00:00 2001 From: Sylvain Wallez Date: Thu, 11 Apr 2024 17:33:03 +0200 Subject: [PATCH] Make linter happy --- compiler/src/transform/expand-generics.ts | 24 +++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/compiler/src/transform/expand-generics.ts b/compiler/src/transform/expand-generics.ts index b69494fec4..ea20e5cd55 100644 --- a/compiler/src/transform/expand-generics.ts +++ b/compiler/src/transform/expand-generics.ts @@ -51,11 +51,10 @@ export class ExpansionConfig { * @return a new model with generics expanded */ export function expandGenerics (inputModel: Model, config?: ExpansionConfig): Model { - const typesToUnwrap = new Set() const typesToInline: Set = new Set() - for (const name of config?.unwrappedTypes || []) { + for (const name of config?.unwrappedTypes ?? []) { if (typeof name === 'string') { typesToUnwrap.add(name) } else { @@ -63,7 +62,7 @@ export function expandGenerics (inputModel: Model, config?: ExpansionConfig): Mo } } - for (const name of config?.inlinedTypes || []) { + for (const name of config?.inlinedTypes ?? []) { if (typeof name === 'string') { typesToInline.add(name) } else { @@ -336,28 +335,29 @@ export function expandGenerics (inputModel: Model, config?: ExpansionConfig): Mo // If this is a type that has to be unwrapped, return its generic parameter's type if (typesToUnwrap.has(valueOfType)) { - // @ts-ignore - return expandValueOf(value.generics[0], mappings) + // @ts-expect-error + const x = value.generics[0] + return expandValueOf(x, mappings) } // If this is a type that has to be inlined if (typesToInline.has(valueOfType)) { // It has to be an alias (e.g. Stringified or WithNullValue const inlinedTypeDef = inputTypeByName.get(valueOfType) - if (!inlinedTypeDef || inlinedTypeDef.kind !== 'type_alias') { + if (inlinedTypeDef?.kind !== 'type_alias') { throw Error(`Inlined type ${valueOfType} should be an alias definition`) } const inlineMappings = new Map() - for (let i = 0; i < (inlinedTypeDef.generics?.length || 0); i++) { - // @ts-ignore + for (let i = 0; i < (inlinedTypeDef.generics?.length ?? 0); i++) { + // @ts-expect-error const source = inlinedTypeDef.generics[i] - // @ts-ignore - const dest = value.generics[i]; + // @ts-expect-error + const dest = value.generics[i] inlineMappings.set(nameKey(source), dest) } - return expandValueOf(inlinedTypeDef.type, inlineMappings); + return expandValueOf(inlinedTypeDef.type, inlineMappings) } // If this is a generic parameter, return its mapping @@ -486,7 +486,7 @@ async function expandGenericsFromFile (inPath: string, outPath: string): Promise const inputModel = JSON.parse(inputText) const outputModel = expandGenerics(inputModel, { // unwrappedTypes: ["_spec_utils:Stringified"], - inlinedTypes: ["_spec_utils:WithNullValue"] + inlinedTypes: ['_spec_utils:WithNullValue'] }) await writeFile(