8000 fix(eslint-plugin): crash in no-unnecessary-type-arguments (#1401) · sstephens/typescript-eslint@01c939f · GitHub
[go: up one dir, main page]

Skip to content

Commit 01c939f

Browse files
armano2bradzacher
andcommitted
fix(eslint-plugin): crash in no-unnecessary-type-arguments (typescript-eslint#1401)
Co-authored-by: Brad Zacher <brad.zacher@gmail.com>
1 parent c5ffe88 commit 01c939f

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ function getTypeParametersFromType(
110110

111111
const sym = getAliasedSymbol(symAtLocation, checker);
112112

113+
if (!sym.declarations) {
114+
return undefined;
115+
}
116+
113117
return findFirstResult(sym.declarations, decl =>
114118
tsutils.isClassLikeDeclaration(decl) ||
115119
ts.isTypeAliasDeclaration(decl) ||

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const rootDir = path.join(process.cwd(), 'tests/fixtures');
66
const ruleTester = new RuleTester({
77
parserOptions: {
88
ecmaVersion: 2015,
9+
sourceType: 'module',
910
tsconfigRootDir: rootDir,
1011
project: './tsconfig.json',
1112
},
@@ -74,6 +75,9 @@ ruleTester.run('no-unnecessary-type-arguments', rule, {
7475
class Foo<T = number> extends Bar<string> {}`,
7576
`interface Bar<T = number> {}
7677
class Foo<T = number> implements Bar<string> {}`,
78+
`import { F } from './missing';
79+
function bar<T = F>() {}
80+
bar<F<number>>()`,
7781
],
7882
invalid: [
7983
{
@@ -177,5 +181,20 @@ ruleTester.run('no-unnecessary-type-arguments', rule, {
177181
output: `class Bar<T = string> {}
178182
class Foo<T = number> extends Bar {}`,
179183
},
184+
{
185+
code: `import { F } from './missing';
186+
function bar<T = F<string>>() {}
187+
bar<F<string>>()`,
188+
errors: [
189+
{
190+
line: 3,
191+
column: 13,
192+
messageId: 'unnecessaryTypeParameter',
193+
},
194+
],
195+
output: `import { F } from './missing';
196+
function bar<T = F<string>>() {}
197+
bar()`,
198+
},
180199
],
181200
});

0 commit comments

Comments
 (0)
0