Skip to content

Commit 6c88912

Browse files
vedadeeptaljharb
authored andcommitted
[Fix] propTypes: handle imported types/interface in forwardRef generic
Fixes #3140
1 parent b7a9c2a commit 6c88912

File tree

3 files changed

+99
-1
lines changed

3 files changed

+99
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
1818
* `propTypes`: add `VFC` to react generic type param map ([#3230][] @dlech)
1919
* [`no-unused-state`]: avoid a crash ([#3258][] @WillyLiaoWH @ljharb)
2020
* [`jsx-no-useless-fragment`]: use proper apostrophe in error message ([#3266][] @develohpanda)
21+
* `propTypes`: handle imported types/interface in forwardRef generic ([#3280][] @vedadeepta)
2122

2223
### Changed
2324
* [readme] remove global usage and eslint version from readme ([#3254][] @aladdin-add)
@@ -31,6 +32,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
3132
* [Refactor] add `isParenthesized` AST util ([#3203][] @Belco90)
3233
* [Docs] `default-props-match-prop-types`, `require-default-props`, `sort-prop-types`: fix typos ([#3279][] @nix6839)
3334

35+
[#3280]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3280
3436
[#3279]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3279
3537
[#3273]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3273
3638
[#3272]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3272

lib/util/propTypes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ module.exports = function propTypesInstructions(context, components, utils) {
10161016
const obj = new DeclarePropTypesForTSTypeAnnotation(propTypes, declaredPropTypes);
10171017
components.set(node, {
10181018
declaredPropTypes: obj.declaredPropTypes,
1019-
ignorePropsValidation: false,
1019+
ignorePropsValidation: obj.shouldIgnorePropTypes,
10201020
});
10211021
return;
10221022
}

tests/lib/rules/prop-types.js

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4042,6 +4042,102 @@ ruleTester.run('prop-types', rule, {
40424042
}}
40434043
/>
40444044
`,
4045+
},
4046+
{
4047+
code: `
4048+
import React, { forwardRef } from 'react';
4049+
import { ControlProps, NamedProps } from './ext';
4050+
4051+
type ButtonProps = ControlProps & NamedProps & {
4052+
onClick?: (() => void) | undefined;
4053+
onMouseDown?: (() => void) | undefined;
4054+
onMouseUp?: (() => void) | undefined;
4055+
disabled?: boolean | undefined;
4056+
width?: number;
4057+
type?: 'submit' | 'reset' | 'button' | undefined;
4058+
};
4059+
4060+
const BaseButton = forwardRef<HTMLButtonElement, ButtonProps>((
4061+
{
4062+
name,
4063+
className,
4064+
onClick,
4065+
onMouseDown,
4066+
onMouseUp,
4067+
children,
4068+
disabled,
4069+
width,
4070+
type,
4071+
},
4072+
ref,
4073+
): JSX.Element => {
4074+
return <span>{width}</span>;
4075+
});
4076+
`,
4077+
features: ['ts', 'no-babel'],
4078+
},
4079+
{
4080+
code: `
4081+
import React, { forwardRef } from 'react';
4082+
import { ControlProps, NamedProps } from './ext';
4083+
4084+
interface ButtonProps extends NamedProps {
4085+
onClick?: (() => void) | undefined;
4086+
onMouseDown?: (() => void) | undefined;
4087+
onMouseUp?: (() => void) | undefined;
4088+
disabled?: boolean | undefined;
4089+
width?: number;
4090+
type?: 'submit' | 'reset' | 'button' | undefined;
4091+
};
4092+
4093+
const BaseButton = forwardRef<HTMLButtonElement, ButtonProps>((
4094+
{
4095+
name,
4096+
className,
4097+
onClick,
4098+
onMouseDown,
4099+
onMouseUp,
4100+
children,
4101+
disabled,
4102+
width,
4103+
type,
4104+
},
4105+
ref,
4106+
): JSX.Element => {
4107+
return <span>{width}</span>;
4108+
});
4109+
`,
4110+
features: ['ts', 'no-babel'],
4111+
},
4112+
{
4113+
code: `
4114+
import React, { forwardRef } from 'react';
4115+
import { IExt1 } from './ext';
4116+
4117+
interface IProps extends IExt1 {
4118+
onClick?: (() => void) | undefined;
4119+
onMouseDown?: (() => void) | undefined;
4120+
onMouseUp?: (() => void) | undefined;
4121+
disabled?: boolean | undefined;
4122+
width?: number;
4123+
type?: 'submit' | 'reset' | 'button' | undefined;
4124+
};
4125+
4126+
const Button: React.FC<IProps> = ({
4127+
name,
4128+
className,
4129+
onClick,
4130+
onMouseDown,
4131+
onMouseUp,
4132+
children,
4133+
disabled,
4134+
width,
4135+
type,
4136+
}): JSX.Element => {
4137+
return <span>{width}</span>;
4138+
};
4139+
`,
4140+
features: ['ts', 'no-babel'],
40454141
}
40464142
)),
40474143

0 commit comments

Comments
 (0)