Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
First fixes based on code review feedback
  • Loading branch information
blickly committed Aug 19, 2024
commit de61d6dadc71effd20bec0e99df8b598e198e339
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 {

Comment thread
blickly marked this conversation as resolved.
Outdated
/** @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) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cutoff can't be undefined; should this instead be a check that skips this block if the length is different than the existing node?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Done.

// 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);
Comment thread
jakebailey marked this conversation as resolved.
Outdated
}
}
Expand Down