diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 9e635cafd13a3..aafdc1afc28b9 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -5032,8 +5032,6 @@ export interface TypeCheckerHost extends ModuleSpecifierResolutionHost { export interface TypeChecker { - /** @internal */ - fillMissingTypeArguments(typeArguments: readonly Type[], typeParameters: readonly TypeParameter[] | undefined, minTypeArgumentCount: number, isJavaScriptImplicitAny: boolean): Type[]; getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type; getTypeOfSymbol(symbol: Symbol): Type; getDeclaredTypeOfSymbol(symbol: Symbol): Type; @@ -5397,6 +5395,7 @@ export interface TypeChecker { /** @internal */ isTypeParameterPossiblyReferenced(tp: TypeParameter, node: Node): boolean; /** @internal */ typeHasCallOrConstructSignatures(type: Type): boolean; /** @internal */ getSymbolFlags(symbol: Symbol): SymbolFlags; + /** @internal */ fillMissingTypeArguments(typeArguments: readonly Type[], typeParameters: readonly TypeParameter[] | undefined, minTypeArgumentCount: number, isJavaScriptImplicitAny: boolean): Type[]; } /** @internal */ diff --git a/src/services/codefixes/helpers.ts b/src/services/codefixes/helpers.ts index f71f66bac3d17..e29ac09fb59dd 100644 --- a/src/services/codefixes/helpers.ts +++ b/src/services/codefixes/helpers.ts @@ -619,10 +619,9 @@ export function typeNodeToAutoImportableTypeNode(typeNode: TypeNode, importAdder return getSynthesizedDeepClone(typeNode); } -function endOfRequiredTypeParameters(checker: TypeChecker, type: GenericType, fullTypeArguments: readonly Type[]) : number { - if (fullTypeArguments !== type.typeArguments!) { - throw new Error('fullTypeArguments should be set') - } +function endOfRequiredTypeParameters(checker: TypeChecker, type: GenericType): number { + Debug.assert(type.typeArguments); + const fullTypeArguments = type.typeArguments; const target = type.target; next_cutoff: for (let cutoff = 0; cutoff < fullTypeArguments.length; cutoff++) { const typeArguments = fullTypeArguments.slice(0, cutoff); @@ -635,7 +634,7 @@ function endOfRequiredTypeParameters(checker: TypeChecker, type: GenericType, fu } // If we make it all the way here, all the type arguments are required. return fullTypeArguments.length; - } +} export function typeToMinimizedReferenceType(checker: TypeChecker, type: Type, contextNode: Node | undefined, flags?: NodeBuilderFlags, internalFlags?: InternalNodeBuilderFlags, tracker?: SymbolTracker): TypeNode | undefined { const typeNode = checker.typeToTypeNode(type, contextNode, flags, internalFlags, tracker); @@ -645,9 +644,9 @@ export function typeToMinimizedReferenceType(checker: TypeChecker, type: Type, c if (isTypeReferenceNode(typeNode)) { const genericType = type as GenericType; if (genericType.typeArguments) { - const cutoff = endOfRequiredTypeParameters(checker, genericType, genericType.typeArguments); + const cutoff = endOfRequiredTypeParameters(checker, genericType); if (cutoff !== undefined && typeNode.typeArguments) { - // Looks like the wrong way to do this. What APIs should I use here? + // Cast to any to mutate the newly created TypeNode (typeNode as any).typeArguments = typeNode.typeArguments.slice(0, cutoff); } }