Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ function getTypeParametersFromNode(
if (
ts.isCallExpression(tsNode) ||
ts.isNewExpression(tsNode) ||
ts.isTaggedTemplateExpression(tsNode)
ts.isTaggedTemplateExpression(tsNode) ||
ts.isJsxOpeningElement(tsNode) ||
ts.isJsxSelfClosingElement(tsNode)
) {
return getTypeParametersFromCall(node, tsNode, checker);
}
Expand Down Expand Up @@ -189,7 +191,12 @@ function getTypeParametersFromType(

function getTypeParametersFromCall(
node: TSESTree.TSTypeParameterInstantiation,
tsNode: ts.CallExpression | ts.NewExpression | ts.TaggedTemplateExpression,
tsNode:
| ts.CallExpression
| ts.JsxOpeningElement
| ts.JsxSelfClosingElement
| ts.NewExpression
| ts.TaggedTemplateExpression,
checker: ts.TypeChecker,
): readonly ts.TypeParameterDeclaration[] | undefined {
const sig = checker.getResolvedSignature(tsNode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,36 @@ namespace Foo {
}
class Bar extends Foo<string> {}
`,
{
code: `
function Button<T>() {
return <div></div>;
}
const button = <Button<string>></Button>;
`,
languageOptions: {
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
},
},
{
code: `
function Button<T>() {
return <div></div>;
}
const button = <Button<string> />;
`,
languageOptions: {
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
},
},
],
invalid: [
{
Expand Down Expand Up @@ -560,5 +590,59 @@ namespace Foo {
class Bar extends Foo {}
`,
},
{
code: `
function Button<T = string>() {
return <div></div>;
}
const button = <Button<string>></Button>;
`,
errors: [
{
line: 5,
messageId: 'unnecessaryTypeParameter',
},
],
languageOptions: {
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
},
output: `
function Button<T = string>() {
return <div></div>;
}
const button = <Button></Button>;
`,
},
{
code: `
function Button<T = string>() {
return <div></div>;
}
const button = <Button<string> />;
`,
errors: [
{
line: 5,
messageId: 'unnecessaryTypeParameter',
},
],
languageOptions: {
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
},
output: `
function Button<T = string>() {
return <div></div>;
}
const button = <Button />;
`,
},
],
});
Loading