Skip to content

Commit

Permalink
fix(eslint-plugin): [no-unnec-type-arg] throwing on call/new expr (#1217
Browse files Browse the repository at this point in the history
)

Co-authored-by: Brad Zacher <brad.zacher@gmail.com>
  • Loading branch information
a-tarasyuk and bradzacher committed Nov 17, 2019
1 parent ba89168 commit 42a48de
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Expand Up @@ -114,7 +114,11 @@ function getTypeParametersFromNode(
return getTypeParametersFromType(node.typeName, checker);
}

return getTypeParametersFromCall(node, checker);
if (ts.isCallExpression(node) || ts.isNewExpression(node)) {
return getTypeParametersFromCall(node, checker);
}

return undefined;
}

function getTypeParametersFromType(
Expand Down
Expand Up @@ -53,6 +53,9 @@ ruleTester.run('no-unnecessary-type-arguments', rule, {
`declare const C: unknown;
class D<TD = number> extends C { }`,
`let a: A<number>`,
`class Foo<T> {}
const foo = new Foo<number>();`,
`type Foo<T> = import('foo').Foo<T>;`,
],
invalid: [
{
Expand Down Expand Up @@ -123,5 +126,16 @@ ruleTester.run('no-unnecessary-type-arguments', rule, {
output: `interface I<T = number> { }
class Impl implements I { }`,
},
{
code: `class Foo<T = number> {}
const foo = new Foo<number>();`,
errors: [
{
messageId: 'unnecessaryTypeParameter',
},
],
output: `class Foo<T = number> {}
const foo = new Foo();`,
},
],
});

0 comments on commit 42a48de

Please sign in to comment.