Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cdf9294

Browse files
fix(eslint-plugin): [no-unnec-type-arg] undefined symbol crash (typescript-eslint#1007)
1 parent 6279c5b commit cdf9294

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

packages/eslint-plugin/src/rules/no-unnecessary-type-arguments.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,12 @@ function getTypeParametersFromType(
121121
type: ts.EntityName | ts.Expression | ts.ClassDeclaration,
122122
checker: ts.TypeChecker,
123123
): readonly ts.TypeParameterDeclaration[] | undefined {
124-
const sym = getAliasedSymbol(checker.getSymbolAtLocation(type)!, checker);
124+
const symAtLocation = checker.getSymbolAtLocation(type);
125+
if (symAtLocation === undefined) {
126+
return undefined;
127+
}
128+
129+
const sym = getAliasedSymbol(symAtLocation, checker);
125130
if (sym === undefined || sym.declarations === undefined) {
126131
return undefined;
127132
}

packages/eslint-plugin/tests/rules/no-unnecessary-type-arguments.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ ruleTester.run('no-unnecessary-type-arguments', rule, {
5252
class D<TD = number> extends C { }`,
5353
`declare const C: unknown;
5454
class D<TD = number> extends C { }`,
55+
`let a: A<number>`,
5556
],
5657
invalid: [
5758
{

0 commit comments

Comments
 (0)