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

[Bug]: [react/prop-types] False positive when using FC-derived custom type for Functional Components #3873

Open
2 tasks done
HazyFish opened this issue Jan 7, 2025 · 3 comments

Comments

@HazyFish
Copy link

HazyFish commented Jan 7, 2025

Is there an existing issue for this?

  • I have searched the existing issues and my issue is unique
  • My issue appears in the command-line and not only in the text editor

Description Overview

Creating a type alias for a functional component will result in false positive for rule react/prop-types

Minimal Reproduction

import { FC } from "react";

type XFC = FC<{ user: string }>;

export const MyComponent: XFC = ({ user }) => {  // ERROR: react/prop-types
    // ...
};
import { FC } from "react";

export const MyComponent: FC<{ user: string }> = ({ user }) => {  // OK
    // ...
};

Expected Behavior

There should be no ESLint error

eslint-plugin-react version

v7.37.3

eslint version

v9.17.0

node version

v22.12.0

@HazyFish HazyFish added the bug label Jan 7, 2025
@ljharb
Copy link
Member

ljharb commented Jan 7, 2025

Following variable references is tricky, unfortunately, but I'm happy to accept a PR here.

@HazyFish
Copy link
Author

HazyFish commented Jan 8, 2025

I'm not familiar with how this plugin is implemented, but since TypeScript is able to infer the type, can we safely disable this rule in a TypeScript project? Any violations that TypeScript cannot catch?

@ljharb
Copy link
Member

ljharb commented Jan 8, 2025

If you're using React < 19 and actual propTypes, then there's tons; but with only TS types and/or with React 19+, the primary benefit is ensuring that your components have types at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants