Skip to content

Commit

Permalink
fix(eslint-plugin): crash in no-unnecessary-type-arguments (#1401)
Browse files Browse the repository at this point in the history
Co-authored-by: Brad Zacher <brad.zacher@gmail.com>
  • Loading branch information
armano2 and bradzacher committed Jan 2, 2020
1 parent c5ffe88 commit 01c939f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Expand Up @@ -110,6 +110,10 @@ function getTypeParametersFromType(

const sym = getAliasedSymbol(symAtLocation, checker);

if (!sym.declarations) {
return undefined;
}

return findFirstResult(sym.declarations, decl =>
tsutils.isClassLikeDeclaration(decl) ||
ts.isTypeAliasDeclaration(decl) ||
Expand Down
Expand Up @@ -6,6 +6,7 @@ const rootDir = path.join(process.cwd(), 'tests/fixtures');
const ruleTester = new RuleTester({
parserOptions: {
ecmaVersion: 2015,
sourceType: 'module',
tsconfigRootDir: rootDir,
project: './tsconfig.json',
},
Expand Down Expand Up @@ -74,6 +75,9 @@ ruleTester.run('no-unnecessary-type-arguments', rule, {
class Foo<T = number> extends Bar<string> {}`,
`interface Bar<T = number> {}
class Foo<T = number> implements Bar<string> {}`,
`import { F } from './missing';
function bar<T = F>() {}
bar<F<number>>()`,
],
invalid: [
{
Expand Down Expand Up @@ -177,5 +181,20 @@ ruleTester.run('no-unnecessary-type-arguments', rule, {
output: `class Bar<T = string> {}
class Foo<T = number> extends Bar {}`,
},
{
code: `import { F } from './missing';
function bar<T = F<string>>() {}
bar<F<string>>()`,
errors: [
{
line: 3,
column: 13,
messageId: 'unnecessaryTypeParameter',
},
],
output: `import { F } from './missing';
function bar<T = F<string>>() {}
bar()`,
},
],
});

0 comments on commit 01c939f

Please sign in to comment.