Skip to content

Commit

Permalink
First fixes based on code review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
blickly committed Aug 19, 2024
1 parent b0bc68f commit de61d6d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
3 changes: 1 addition & 2 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down
13 changes: 6 additions & 7 deletions src/services/codefixes/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
}
}
Expand Down

0 comments on commit de61d6d

Please sign in to comment.