Skip to content

Commit 227e967

Browse files
vedadeeptaljharb
authored andcommitted
[Fix] prop-types, propTypes: bail out unknown generic types inside func params
1 parent bd270fc commit 227e967

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed

CHANGELOG.md

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

66
## Unreleased
77

8+
### Fixed
9+
* [`prop-types`], `propTypes`: bail out unknown generic types inside func params ([#3076] @vedadeepta)
10+
11+
[#3076]: https://github.com/yannickcr/eslint-plugin-react/pull/3076
12+
813
## [7.25.2] - 2021.09.16
914

1015
### Fixed

lib/util/propTypes.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -970,16 +970,6 @@ module.exports = function propTypesInstructions(context, components, utils) {
970970
}
971971
});
972972
} else {
973-
// check if its a valid generic type when `X<{...}>`
974-
if (
975-
param.typeAnnotation
976-
&& param.typeAnnotation.typeAnnotation
977-
&& param.typeAnnotation.typeAnnotation.type === 'TSTypeReference'
978-
&& param.typeAnnotation.typeAnnotation.typeParameters != null
979-
&& !isValidReactGenericTypeAnnotation(param.typeAnnotation.typeAnnotation)
980-
) {
981-
return;
982-
}
983973
markPropTypesAsDeclared(node, resolveTypeAnnotation(param));
984974
}
985975
} else {

tests/lib/rules/prop-types.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3303,6 +3303,19 @@ ruleTester.run('prop-types', rule, {
33033303
33043304
`,
33053305
parser: parsers['@TYPESCRIPT_ESLINT']
3306+
},
3307+
{
3308+
code: `
3309+
type Props<ValueType> = {
3310+
value: ValueType;
3311+
onClick: (value: ValueType) => void;
3312+
};
3313+
3314+
const Button = <T,>({ onClick, value }: Props<T>) => {
3315+
return <button onClick={() => onClick(value)}>BUTTON</button>;
3316+
};
3317+
`,
3318+
parser: parsers['@TYPESCRIPT_ESLINT']
33063319
}
33073320
]),
33083321
{
@@ -6865,6 +6878,23 @@ ruleTester.run('prop-types', rule, {
68656878
}
68666879
],
68676880
parser: parsers['@TYPESCRIPT_ESLINT']
6881+
},
6882+
{
6883+
code: `
6884+
type PersonProps<T> = {
6885+
x: T;
6886+
}
6887+
const Person = (props: PersonProps<string>): React.ReactElement => (
6888+
<div>{props.username}</div>
6889+
);
6890+
`,
6891+
errors: [
6892+
{
6893+
messageId: 'missingPropType',
6894+
data: {name: 'username'}
6895+
}
6896+
],
6897+
parser: parsers['@TYPESCRIPT_ESLINT']
68686898
}
68696899
])
68706900
)

0 commit comments

Comments
 (0)