Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] no-unused-prop-types: Silence false positive on never type in TS #2815

Merged
merged 1 commit into from Oct 3, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG.md
Expand Up @@ -5,9 +5,14 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel

## Unreleased

### Fixed
* [`no-unused-prop-types`]: Silence false positive on `never` type in TS ([#2815][] @pcorpet)

[#2815]: https://github.com/yannickcr/eslint-plugin-react/pull/2815

## [7.21.3] - 2020.10.02

## Fixed
### Fixed
* [`prop-types`]: fix Cannot read property 'type' of undefined error when destructured param ([#2807][] @minwe)
* [`no-typos`]: avoid crash on spread syntax in createReactClass object ([#2816][] @ljharb @Songyu-Wang)

Expand Down
5 changes: 5 additions & 0 deletions lib/rules/no-unused-prop-types.js
Expand Up @@ -102,6 +102,11 @@ module.exports = {
return;
}

if (prop.node && prop.node.typeAnnotation && prop.node.typeAnnotation.typeAnnotation
&& prop.node.typeAnnotation.typeAnnotation.type === 'TSNeverKeyword') {
return;
}

if (prop.node && !isPropUsed(component, prop)) {
context.report({
node: prop.node.key || prop.node,
Expand Down
13 changes: 13 additions & 0 deletions tests/lib/rules/no-unused-prop-types.js
Expand Up @@ -3668,6 +3668,19 @@ ruleTester.run('no-unused-prop-types', rule, {
`,
parser: parsers['@TYPESCRIPT_ESLINT']
},
{
code: `
interface Person {
firstname: string
lastname?: never
};

const Hello = ({firstname}: Person) => {
return <div><span>{firstname}</span></div>;
};
`,
parser: parsers['@TYPESCRIPT_ESLINT']
},
{
code: `
class App extends Component {
Expand Down