Skip to content

Commit 37b4f8e

Browse files
dlechljharb
authored andcommitted
[Fix] propTypes: add VFC to react generic param map
In d9531c3, we missed adding VFC to genericTypeParamIndexWherePropsArePresent in addition to allowedGenericTypes. This adds some failing tests and fixes the issue. Fixes #3230
1 parent cab6943 commit 37b4f8e

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
77

88
### Fixed
99
* [`hook-use-state`]: Allow UPPERCASE setState setter prefixes ([#3244][] @duncanbeevers)
10+
* `propTypes`: add `VFC` to react generic type param map ([#3230][] @dlech)
1011

1112
[#3244]: https://github.com/yannickcr/eslint-plugin-react/pull/3244
13+
[#3230]: https://github.com/yannickcr/eslint-plugin-react/issues/3230
1214

1315
## [7.29.4] - 2022.03.13
1416

lib/util/propTypes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ module.exports = function propTypesInstructions(context, components, utils) {
105105
ForwardRefRenderFunction: 1,
106106
forwardRef: 1,
107107
VoidFunctionComponent: 0,
108+
VFC: 0,
108109
PropsWithChildren: 0,
109110
SFC: 0,
110111
StatelessComponent: 0,

tests/lib/rules/prop-types.js

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3439,6 +3439,51 @@ ruleTester.run('prop-types', rule, {
34393439
`,
34403440
features: ['ts', 'no-babel'],
34413441
},
3442+
{
3443+
code: `
3444+
import React, { VFC } from 'react'
3445+
3446+
interface Props {
3447+
age: number
3448+
}
3449+
const Hello: VFC<Props> = function Hello(props) {
3450+
const { age } = props;
3451+
3452+
return <div>Hello {age}</div>;
3453+
}
3454+
`,
3455+
features: ['ts', 'no-babel'],
3456+
},
3457+
{
3458+
code: `
3459+
import React from 'react'
3460+
3461+
interface Props {
3462+
age: number
3463+
}
3464+
const Hello: React.VFC<Props> = function Hello(props) {
3465+
const { age } = props;
3466+
3467+
return <div>Hello {age}</div>;
3468+
}
3469+
`,
3470+
features: ['ts', 'no-babel'],
3471+
},
3472+
{
3473+
code: `
3474+
import React from 'react'
3475+
3476+
export interface Props {
3477+
age: number
3478+
}
3479+
const Hello: React.VFC<Props> = function Hello(props) {
3480+
const { age } = props;
3481+
3482+
return <div>Hello {age}</div>;
3483+
}
3484+
`,
3485+
features: ['ts', 'no-babel'],
3486+
},
34423487
{
34433488
code: `
34443489
import React, { ForwardRefRenderFunction as X } from 'react'
@@ -3974,13 +4019,13 @@ ruleTester.run('prop-types', rule, {
39744019
interface SomeType<ContextType = any> {
39754020
renderValue: (context: ContextType) => React.ReactNode;
39764021
}
3977-
4022+
39784023
interface DataObject {
39794024
id: string,
39804025
title: string,
39814026
value: string,
39824027
}
3983-
4028+
39844029
const someType: SomeType<DataObject> = {
39854030
renderValue: ({title}) => <div>{title}</div>,
39864031
};

0 commit comments

Comments
 (0)