Skip to content

Commit 4b509af

Browse files
committed
[Fix] prop-types, propTypes: prevent crash introduced in #3051
Fixes #3053
1 parent 6f78b75 commit 4b509af

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
2424
* [`jsx-no-bind`]: handle local function declarations ([#3048][] @p7g)
2525
* [`prop-types`], `propTypes`: handle React.* TypeScript types ([#3049][] @vedadeepta)
2626
* [`prop-types`], `propTypes`: add handling for `FC<Props>`, improve tests ([#3051][] @vedadeepta)
27+
* [`prop-types`], `propTypes`: prevent crash introduced in [#3051][] ([#3053][] @ljharb)
2728

2829
### Changed
2930
* [Docs] [`jsx-no-bind`]: updates discussion of refs ([#2998][] @dimitropoulos)
@@ -34,6 +35,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
3435
* [Docs] improve instructions for `jsx-runtime` config ([#3052][] @ljharb)
3536

3637
[bb64df65]: https://github.com/yannickcr/eslint-plugin-react/commit/bb64df6505b3e9a01da5b61626ab9f544caea438
38+
[#3053]: https://github.com/yannickcr/eslint-plugin-react/issues/3053
3739
[#3052]: https://github.com/yannickcr/eslint-plugin-react/issues/3052
3840
[#3051]: https://github.com/yannickcr/eslint-plugin-react/pull/3051
3941
[#3049]: https://github.com/yannickcr/eslint-plugin-react/pull/3049

lib/util/propTypes.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -942,17 +942,19 @@ module.exports = function propTypesInstructions(context, components, utils) {
942942
return;
943943
}
944944

945-
if (annotation.typeName.name) { // if FC<Props>
946-
const typeName = annotation.typeName.name;
947-
if (!genericReactTypesImport.has(typeName)) {
948-
return;
949-
}
950-
} else if (annotation.typeName.right.name) { // if React.FC<Props>
951-
const right = annotation.typeName.right.name;
952-
const left = annotation.typeName.left.name;
945+
if (annotation.typeName) {
946+
if (annotation.typeName.name) { // if FC<Props>
947+
const typeName = annotation.typeName.name;
948+
if (!genericReactTypesImport.has(typeName)) {
949+
return;
950+
}
951+
} else if (annotation.typeName.right.name) { // if React.FC<Props>
952+
const right = annotation.typeName.right.name;
953+
const left = annotation.typeName.left.name;
953954

954-
if (!genericReactTypesImport.has(left) || !allowedGenericTypes.has(right)) {
955-
return;
955+
if (!genericReactTypesImport.has(left) || !allowedGenericTypes.has(right)) {
956+
return;
957+
}
956958
}
957959
}
958960
markPropTypesAsDeclared(node, resolveTypeAnnotation(siblingIdentifier));

tests/lib/rules/prop-types.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3280,6 +3280,18 @@ ruleTester.run('prop-types', rule, {
32803280
};
32813281
`,
32823282
parser: parsers['@TYPESCRIPT_ESLINT']
3283+
},
3284+
{
3285+
code: `
3286+
export const EuiSuperSelectControl: <T extends string>(
3287+
props: EuiSuperSelectControlProps<T>
3288+
) => ReturnType<FunctionComponent<EuiSuperSelectControlProps<T>>> = ({
3289+
...rest
3290+
}) => {
3291+
return null;
3292+
}
3293+
`,
3294+
parser: parsers['@TYPESCRIPT_ESLINT']
32833295
}
32843296
]),
32853297
{

0 commit comments

Comments
 (0)