Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] propTypes: add VFC to react generic param map #3246

Merged
merged 1 commit into from Mar 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -7,8 +7,10 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange

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

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

## [7.29.4] - 2022.03.13

Expand Down
1 change: 1 addition & 0 deletions lib/util/propTypes.js
Expand Up @@ -105,6 +105,7 @@ module.exports = function propTypesInstructions(context, components, utils) {
ForwardRefRenderFunction: 1,
forwardRef: 1,
VoidFunctionComponent: 0,
VFC: 0,
PropsWithChildren: 0,
SFC: 0,
StatelessComponent: 0,
Expand Down
49 changes: 47 additions & 2 deletions tests/lib/rules/prop-types.js
Expand Up @@ -3439,6 +3439,51 @@ ruleTester.run('prop-types', rule, {
`,
features: ['ts', 'no-babel'],
},
{
code: `
import React, { VFC } from 'react'
interface Props {
age: number
}
const Hello: VFC<Props> = function Hello(props) {
const { age } = props;
return <div>Hello {age}</div>;
}
`,
features: ['ts', 'no-babel'],
},
{
code: `
import React from 'react'
interface Props {
age: number
}
const Hello: React.VFC<Props> = function Hello(props) {
const { age } = props;
return <div>Hello {age}</div>;
}
`,
features: ['ts', 'no-babel'],
},
{
code: `
import React from 'react'
export interface Props {
age: number
}
const Hello: React.VFC<Props> = function Hello(props) {
const { age } = props;
return <div>Hello {age}</div>;
}
`,
features: ['ts', 'no-babel'],
},
{
code: `
import React, { ForwardRefRenderFunction as X } from 'react'
Expand Down Expand Up @@ -3974,13 +4019,13 @@ ruleTester.run('prop-types', rule, {
interface SomeType<ContextType = any> {
renderValue: (context: ContextType) => React.ReactNode;
}
interface DataObject {
id: string,
title: string,
value: string,
}
const someType: SomeType<DataObject> = {
renderValue: ({title}) => <div>{title}</div>,
};
Expand Down