Skip to content

Commit 71a0e8f

Browse files
pcorpetljharb
authored andcommitted
[Fix] no-unused-prop-types: Silence false positive on never type in TS
1 parent e3e61e3 commit 71a0e8f

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
55

66
## Unreleased
77

8+
### Fixed
9+
* [`no-unused-prop-types`]: Silence false positive on `never` type in TS ([#2815][] @pcorpet)
10+
11+
[#2815]: https://github.com/yannickcr/eslint-plugin-react/pull/2815
12+
813
## [7.21.3] - 2020.10.02
914

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

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ module.exports = {
102102
return;
103103
}
104104

105+
if (prop.node && prop.node.typeAnnotation && prop.node.typeAnnotation.typeAnnotation
106+
&& prop.node.typeAnnotation.typeAnnotation.type === 'TSNeverKeyword') {
107+
return;
108+
}
109+
105110
if (prop.node && !isPropUsed(component, prop)) {
106111
context.report({
107112
node: prop.node.key || prop.node,

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3668,6 +3668,19 @@ ruleTester.run('no-unused-prop-types', rule, {
36683668
`,
36693669
parser: parsers['@TYPESCRIPT_ESLINT']
36703670
},
3671+
{
3672+
code: `
3673+
interface Person {
3674+
firstname: string
3675+
lastname?: never
3676+
};
3677+
3678+
const Hello = ({firstname}: Person) => {
3679+
return <div><span>{firstname}</span></div>;
3680+
};
3681+
`,
3682+
parser: parsers['@TYPESCRIPT_ESLINT']
3683+
},
36713684
{
36723685
code: `
36733686
class App extends Component {

0 commit comments

Comments
 (0)