jsx-eslint/eslint-plugin-react

Bug: `no-unused-prop-types` doesn't detect unused props with Typescript & React 17 jsx transform

Open

#3,336 opened on Jul 13, 2022

View on GitHub
 (6 comments) (1 reaction) (0 assignees)JavaScript (2,797 forks)batch import
bughelp wantedtypescript

Repository metrics

Stars
 (8,630 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

The rule react/no-unused-prop-types doesn't seem to pick up that the component has unused props.

Environment:

Dependencies:

"typescript": "4.6.3",
"eslint-plugin-react": "7.30.1",
"@typescript-eslint/eslint-plugin": "5.29.0",
"@typescript-eslint/parser": "5.29.0",

eslintrc.js

module.exports = {
  rules: [
    'react/no-unused-prop-types': 'error',
  ],
  parser: '@typescript-eslint/parser',
  parserOptions: {
    ecmaFeatures: {
      jsx: true,
    },
    ecmaVersion: 11,
    project: './tsconfig.json',
  },

tsconfig.json

{
  "compilerOptions": {
   /* other config doesn't seem to matter*/
    "jsx": "react-jsx",
  },
}

Example Code

  type Props = {
    username: string;
  }

  const App: React.VFC<Props> = (props) => {
    return <div></div>;
  }

Expected Outcome

Lint error with message 'username' PropType is defined but prop is never used.

Actual Outcome

No error message.


If I change the code to have import React from 'react' at the top of the file, the rule works as expected.

Contributor guide