Skip to content

Commit

Permalink
[Fix] propTypes: add VFC to react generic param map
Browse files Browse the repository at this point in the history
In d9531c3, we missed adding VFC to genericTypeParamIndexWherePropsArePresent in addition to allowedGenericTypes.

This adds some failing tests and fixes the issue.

Fixes jsx-eslint#3230
  • Loading branch information
dlech authored and ljharb committed Mar 16, 2022
1 parent cab6943 commit 37b4f8e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
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

0 comments on commit 37b4f8e

Please sign in to comment.