Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle undefined typeParameters #1495

Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions src/shared/nodeTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ export type NodeWithDefinedTypeArguments = ts.Node & {

// TODO: make this a more specific type
// Will have to deal with instantiations (new Container<T>() { ... }) and declarations (class Container<T>() { ... }))
export type NodeWithDefinedTypeParameters = ts.Node & {
typeParameters: ts.NodeArray<ts.TypeNode>;
export type NodeWithTypeParameters = ts.Node & {
typeParameters: ts.NodeArray<ts.TypeNode> | undefined;
};

export const isNodeWithType = (
Expand All @@ -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;
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(function () {
interface Shape {
value?: unknown;
}

[].reduce<Shape>(() => ({}), {});
})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(function () {
interface Shape {
value?: unknown;
}

[].reduce<Shape>(() => ({}), {});
})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"files": ["actual.ts"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"fixes": {
"incompleteTypes": true
}
}
Loading