Skip to content

Commit

Permalink
[Fix] no-unused-prop-types: Silence false positive on never type …
Browse files Browse the repository at this point in the history
…in TS
  • Loading branch information
pcorpet authored and ljharb committed Oct 1, 2020
1 parent e3e61e3 commit 71a0e8f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
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

0 comments on commit 71a0e8f

Please sign in to comment.