diff --git a/CHANGELOG.md b/CHANGELOG.md index 403fcaeb08..963d7a0663 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel ## Unreleased +### Fixed +* [`prop-types`], `propTypes`: bail out unknown generic types inside func params ([#3076] @vedadeepta) + +[#3076]: https://github.com/yannickcr/eslint-plugin-react/pull/3076 + ## [7.25.2] - 2021.09.16 ### Fixed diff --git a/lib/util/propTypes.js b/lib/util/propTypes.js index 24b83a579e..b9e397deb7 100644 --- a/lib/util/propTypes.js +++ b/lib/util/propTypes.js @@ -970,16 +970,6 @@ module.exports = function propTypesInstructions(context, components, utils) { } }); } else { - // check if its a valid generic type when `X<{...}>` - if ( - param.typeAnnotation - && param.typeAnnotation.typeAnnotation - && param.typeAnnotation.typeAnnotation.type === 'TSTypeReference' - && param.typeAnnotation.typeAnnotation.typeParameters != null - && !isValidReactGenericTypeAnnotation(param.typeAnnotation.typeAnnotation) - ) { - return; - } markPropTypesAsDeclared(node, resolveTypeAnnotation(param)); } } else { diff --git a/tests/lib/rules/prop-types.js b/tests/lib/rules/prop-types.js index d02c5f94a1..55edbbbff7 100644 --- a/tests/lib/rules/prop-types.js +++ b/tests/lib/rules/prop-types.js @@ -3303,6 +3303,19 @@ ruleTester.run('prop-types', rule, { `, parser: parsers['@TYPESCRIPT_ESLINT'] + }, + { + code: ` + type Props = { + value: ValueType; + onClick: (value: ValueType) => void; + }; + + const Button = ({ onClick, value }: Props) => { + return ; + }; + `, + parser: parsers['@TYPESCRIPT_ESLINT'] } ]), { @@ -6865,6 +6878,23 @@ ruleTester.run('prop-types', rule, { } ], parser: parsers['@TYPESCRIPT_ESLINT'] + }, + { + code: ` + type PersonProps = { + x: T; + } + const Person = (props: PersonProps): React.ReactElement => ( +
{props.username}
+ ); + `, + errors: [ + { + messageId: 'missingPropType', + data: {name: 'username'} + } + ], + parser: parsers['@TYPESCRIPT_ESLINT'] } ]) )