Skip to content

Commit

Permalink
feat(eslint-plugin): [no-unnecessary-type-arguments] handle tagged te…
Browse files Browse the repository at this point in the history
…mplates (#8708)
  • Loading branch information
yeonjuan committed Mar 25, 2024
1 parent 2018f91 commit a08554a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
Expand Up @@ -132,7 +132,11 @@ function getTypeParametersFromNode(
return getTypeParametersFromType(node.typeName, checker);
}

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

Expand Down Expand Up @@ -165,7 +169,7 @@ function getTypeParametersFromType(
}

function getTypeParametersFromCall(
node: ts.CallExpression | ts.NewExpression,
node: ts.CallExpression | ts.NewExpression | ts.TaggedTemplateExpression,
checker: ts.TypeChecker,
): readonly ts.TypeParameterDeclaration[] | undefined {
const sig = checker.getResolvedSignature(node);
Expand Down
Expand Up @@ -68,6 +68,14 @@ declare const g: unknown;
g<string, string>();
`,
`
declare const f: unknown;
f<string>\`\`;
`,
`
function f<T = number>(template: TemplateStringsArray) {}
f<string>\`\`;
`,
`
class C<T = number> {}
new C<string>();
`,
Expand Down Expand Up @@ -183,6 +191,22 @@ g<string>();
},
{
code: `
function f<T = number>(templates: TemplateStringsArray, arg: T) {}
f<number>\`\${1}\`;
`,
errors: [
{
column: 3,
messageId: 'unnecessaryTypeParameter',
},
],
output: `
function f<T = number>(templates: TemplateStringsArray, arg: T) {}
f\`\${1}\`;
`,
},
{
code: `
class C<T = number> {}
function h(c: C<number>) {}
`,
Expand Down

0 comments on commit a08554a

Please sign in to comment.