diff --git a/src/mutators/builtIn/fixIncompleteTypes/fixIncompleteInterfaceOrTypeLiteralGenerics/collectGenericNodeReferences.ts b/src/mutators/builtIn/fixIncompleteTypes/fixIncompleteInterfaceOrTypeLiteralGenerics/collectGenericNodeReferences.ts index d0228db784..0f3bdfb3d7 100644 --- a/src/mutators/builtIn/fixIncompleteTypes/fixIncompleteInterfaceOrTypeLiteralGenerics/collectGenericNodeReferences.ts +++ b/src/mutators/builtIn/fixIncompleteTypes/fixIncompleteInterfaceOrTypeLiteralGenerics/collectGenericNodeReferences.ts @@ -4,8 +4,8 @@ import { FileMutationsRequest } from "../../../../shared/fileMutator.js"; import { getIdentifyingTypeLiteralParent, isNodeWithDefinedTypeArguments, - isNodeWithDefinedTypeParameters, isNodeWithIdentifierName, + isNodeWithTypeParameters, } from "../../../../shared/nodeTypes.js"; import { isTypeArgumentsType } from "../../../../shared/typeNodes.js"; import { getTypeAtLocationIfNotError } from "../../../../shared/types.js"; @@ -84,8 +84,9 @@ export const expandReferencesForGenericTypes = ( const templatedDeclaration = templatedDeclarationSymbol.valueDeclaration; if ( templatedDeclaration === undefined || - !isNodeWithDefinedTypeParameters(templatedDeclaration) || - templatedParentInstantiation.typeArguments === undefined + !isNodeWithTypeParameters(templatedDeclaration) || + templatedParentInstantiation.typeArguments === undefined || + templatedDeclaration.typeParameters === undefined ) { continue; } diff --git a/src/shared/nodeTypes.ts b/src/shared/nodeTypes.ts index 12a0004d89..1fef825a78 100644 --- a/src/shared/nodeTypes.ts +++ b/src/shared/nodeTypes.ts @@ -64,8 +64,8 @@ export type NodeWithDefinedTypeArguments = ts.Node & { // TODO: make this a more specific type // Will have to deal with instantiations (new Container() { ... }) and declarations (class Container() { ... })) -export type NodeWithDefinedTypeParameters = ts.Node & { - typeParameters: ts.NodeArray; +export type NodeWithTypeParameters = ts.Node & { + typeParameters: ts.NodeArray | undefined; }; export const isNodeWithType = ( @@ -84,9 +84,9 @@ export const isNodeWithDefinedTypeArguments = ( return "typeArguments" in node; }; -export const isNodeWithDefinedTypeParameters = ( +export const isNodeWithTypeParameters = ( node: ts.Node, -): node is NodeWithDefinedTypeParameters => { +): node is NodeWithTypeParameters => { return "typeParameters" in node; }; diff --git a/test/cases/fixes/incompleteTypes/nonGenericInterfaceAsTypeArgument/expected.ts b/test/cases/fixes/incompleteTypes/nonGenericInterfaceAsTypeArgument/expected.ts new file mode 100644 index 0000000000..9004c7f943 --- /dev/null +++ b/test/cases/fixes/incompleteTypes/nonGenericInterfaceAsTypeArgument/expected.ts @@ -0,0 +1,7 @@ +(function () { + interface Shape { + value?: unknown; + } + + [].reduce(() => ({}), {}); +})(); diff --git a/test/cases/fixes/incompleteTypes/nonGenericInterfaceAsTypeArgument/original.ts b/test/cases/fixes/incompleteTypes/nonGenericInterfaceAsTypeArgument/original.ts new file mode 100644 index 0000000000..9004c7f943 --- /dev/null +++ b/test/cases/fixes/incompleteTypes/nonGenericInterfaceAsTypeArgument/original.ts @@ -0,0 +1,7 @@ +(function () { + interface Shape { + value?: unknown; + } + + [].reduce(() => ({}), {}); +})(); diff --git a/test/cases/fixes/incompleteTypes/nonGenericInterfaceAsTypeArgument/tsconfig.json b/test/cases/fixes/incompleteTypes/nonGenericInterfaceAsTypeArgument/tsconfig.json new file mode 100644 index 0000000000..7de2b9de32 --- /dev/null +++ b/test/cases/fixes/incompleteTypes/nonGenericInterfaceAsTypeArgument/tsconfig.json @@ -0,0 +1,3 @@ +{ + "files": ["actual.ts"] +} diff --git a/test/cases/fixes/incompleteTypes/nonGenericInterfaceAsTypeArgument/typestat.json b/test/cases/fixes/incompleteTypes/nonGenericInterfaceAsTypeArgument/typestat.json new file mode 100644 index 0000000000..1406ae0fa5 --- /dev/null +++ b/test/cases/fixes/incompleteTypes/nonGenericInterfaceAsTypeArgument/typestat.json @@ -0,0 +1,5 @@ +{ + "fixes": { + "incompleteTypes": true + } +}