jsx-eslint/eslint-plugin-react

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

Open

#3.336 aberto em 13 de jul. de 2022

Ver no GitHub
 (6 comments) (1 reaction) (0 assignees)JavaScript (2.797 forks)batch import
bughelp wantedtypescript

Métricas do repositório

Stars
 (8.630 stars)
Métricas de merge de PR
 (Nenhuma PRs mesclada em 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.

Guia do colaborador