Skip to content

Commit 36482a3

Browse files
niikljharb
andcommitted
[Fix] propTypes: Handle TSTypeReference in no-unused-prop-types
Co-authored-by: Markus Olsson <[email protected]> Co-authored-by: Jordan Harband <[email protected]>
1 parent 7463448 commit 36482a3

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
1414
* [`prop-types`], `propTypes`: add support for exported type inference ([#3163][] @vedadeepta)
1515
* [`no-invalid-html-attribute`]: allow 'shortcut icon' on `link` ([#3174][] @Primajin)
1616
* [`prefer-exact-props`] improve performance for `Identifier` visitor ([#3190][] @meowtec)
17+
* `propTypes`: Handle TSTypeReference in no-unused-prop-type ([#3195][] @niik)
1718

1819
### Changed
1920
* [readme] change [`jsx-runtime`] link from branch to sha ([#3160][] @tatsushitoji)
@@ -23,6 +24,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
2324
* [Docs] [`display-name`]: improve examples ([#3189][] @golopot)
2425
* [Refactor] [`no-invalid-html-attribute`]: sort HTML_ELEMENTS and messages ([#3182][] @Primajin)
2526

27+
[#3195]: https://github.com/yannickcr/eslint-plugin-react/pull/3195
2628
[#3191]: https://github.com/yannickcr/eslint-plugin-react/pull/3191
2729
[#3190]: https://github.com/yannickcr/eslint-plugin-react/pull/3190
2830
[#3189]: https://github.com/yannickcr/eslint-plugin-react/pull/3189

lib/util/propTypes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,7 @@ module.exports = function propTypesInstructions(context, components, utils) {
967967
ignorePropsValidation = true;
968968
}
969969
break;
970+
case 'TSTypeReference':
970971
case 'TSTypeAnnotation': {
971972
const tsTypeAnnotation = new DeclarePropTypesForTSTypeAnnotation(propTypes, declaredPropTypes);
972973
ignorePropsValidation = tsTypeAnnotation.shouldIgnorePropTypes;

tests/lib/rules/no-unused-prop-types.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6486,6 +6486,23 @@ ruleTester.run('no-unused-prop-types', rule, {
64866486
};
64876487
`,
64886488
errors: [{ message: '\'foo\' PropType is defined but prop is never used' }],
6489+
},
6490+
6491+
{
6492+
code: `
6493+
interface Props {
6494+
readonly firstname: string;
6495+
readonly lastname: string;
6496+
}
6497+
6498+
class TestComponent extends React.Component<Props> {
6499+
public render() {
6500+
return <div>{this.props.firstname}</div>;
6501+
}
6502+
}
6503+
`,
6504+
features: ['ts', 'no-babel'],
6505+
errors: [{ message: '\'lastname\' PropType is defined but prop is never used' }],
64896506
}
64906507
)),
64916508
});

0 commit comments

Comments
 (0)