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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] propType: ignore imported types/interface in forwardRef generic #3280

Merged
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 @@ -18,6 +18,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
* `propTypes`: add `VFC` to react generic type param map ([#3230][] @dlech)
* [`no-unused-state`]: avoid a crash ([#3258][] @WillyLiaoWH @ljharb)
* [`jsx-no-useless-fragment`]: use proper apostrophe in error message ([#3266][] @develohpanda)
* `propTypes`: handle imported types/interface in forwardRef generic ([#3280][] @vedadeepta)

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

[#3280]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3280
[#3279]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3279
[#3273]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3273
[#3272]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3272
Expand Down
2 changes: 1 addition & 1 deletion lib/util/propTypes.js
Expand Up @@ -1016,7 +1016,7 @@ module.exports = function propTypesInstructions(context, components, utils) {
const obj = new DeclarePropTypesForTSTypeAnnotation(propTypes, declaredPropTypes);
components.set(node, {
declaredPropTypes: obj.declaredPropTypes,
ignorePropsValidation: false,
ignorePropsValidation: obj.shouldIgnorePropTypes,
});
return;
}
Expand Down
96 changes: 96 additions & 0 deletions tests/lib/rules/prop-types.js
Expand Up @@ -4042,6 +4042,102 @@ ruleTester.run('prop-types', rule, {
}}
/>
`,
},
{
code: `
import React, { forwardRef } from 'react';
import { ControlProps, NamedProps } from './ext';

type ButtonProps = ControlProps & NamedProps & {
onClick?: (() => void) | undefined;
onMouseDown?: (() => void) | undefined;
onMouseUp?: (() => void) | undefined;
disabled?: boolean | undefined;
width?: number;
type?: 'submit' | 'reset' | 'button' | undefined;
};

const BaseButton = forwardRef<HTMLButtonElement, ButtonProps>((
{
name,
className,
onClick,
onMouseDown,
onMouseUp,
children,
disabled,
width,
type,
},
ref,
): JSX.Element => {
return <span>{width}</span>;
});
`,
features: ['ts', 'no-babel'],
},
{
code: `
import React, { forwardRef } from 'react';
import { ControlProps, NamedProps } from './ext';

interface ButtonProps extends NamedProps {
onClick?: (() => void) | undefined;
onMouseDown?: (() => void) | undefined;
onMouseUp?: (() => void) | undefined;
disabled?: boolean | undefined;
width?: number;
type?: 'submit' | 'reset' | 'button' | undefined;
};

const BaseButton = forwardRef<HTMLButtonElement, ButtonProps>((
{
name,
className,
onClick,
onMouseDown,
onMouseUp,
children,
disabled,
width,
type,
},
ref,
): JSX.Element => {
return <span>{width}</span>;
});
`,
features: ['ts', 'no-babel'],
},
{
code: `
import React, { forwardRef } from 'react';
import { IExt1 } from './ext';

interface IProps extends IExt1 {
onClick?: (() => void) | undefined;
onMouseDown?: (() => void) | undefined;
onMouseUp?: (() => void) | undefined;
disabled?: boolean | undefined;
width?: number;
type?: 'submit' | 'reset' | 'button' | undefined;
};

const Button: React.FC<IProps> = ({
name,
className,
onClick,
onMouseDown,
onMouseUp,
children,
disabled,
width,
type,
}): JSX.Element => {
return <span>{width}</span>;
};
`,
features: ['ts', 'no-babel'],
}
)),

Expand Down