Commit 6e8f543
Ethan Goldberg
Fix required prop types for classes with annotated methods.
The `react/prop-types` rule incorrectly considers flow type
annotations on class methods with arguments named `props` as
prop type declarations for the class, even though flow itself
gives them no such weight.
When a react component is defined as a class extending `React.Component`,
and it defines a method that takes an annotated argument named `props`,
then, even though flow still thinks the props have `any` type, the
`prop-types` rule will not produce 'missing in props validation' errors.
A pattern that gets used a lot in React components is as follows:
```javascript
type Props = {...};
class Comp extends React.Component {
constructor(props: Props) {
super(props);
// do something...
}
// ...
}
```
which makes this especially nefarious.1 parent ccb213d commit 6e8f543
2 files changed
+39
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
868 | 868 | | |
869 | 869 | | |
870 | 870 | | |
871 | | - | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
872 | 877 | | |
873 | 878 | | |
874 | 879 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1115 | 1115 | | |
1116 | 1116 | | |
1117 | 1117 | | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
1118 | 1132 | | |
1119 | 1133 | | |
1120 | 1134 | | |
| |||
1405 | 1419 | | |
1406 | 1420 | | |
1407 | 1421 | | |
| 1422 | + | |
| 1423 | + | |
| 1424 | + | |
| 1425 | + | |
| 1426 | + | |
| 1427 | + | |
| 1428 | + | |
| 1429 | + | |
| 1430 | + | |
| 1431 | + | |
| 1432 | + | |
| 1433 | + | |
| 1434 | + | |
| 1435 | + | |
| 1436 | + | |
| 1437 | + | |
| 1438 | + | |
| 1439 | + | |
| 1440 | + | |
1408 | 1441 | | |
1409 | 1442 | | |
1410 | 1443 | | |
| |||
0 commit comments