升级到 Typescript 4.4.2 后如何修复“错误 'JSX' 未定义 no-undef”

jac*_*118 6 typescript typescript-typings eslintrc typescript-eslint

error 'x' is not defined no-undef从 typescript 3.8.2 升级到 typescript 4.4.2 后出现很多错误。其中一个例子是error 'JSX' is not defined no-undef,我进行了更深入的研究,大部分是从declarations.d.ts我如何解决它?

"typescript": "4.4.2"
"@typescript-eslint/eslint-plugin": "4.31.0",
"@typescript-eslint/parser": "4.31.0",
Run Code Online (Sandbox Code Playgroud)

fri*_*mle 3

来自typescript-eslint 故障排除指南

我们强烈建议您不要在 TypeScript 项目上使用 no-undef lint 规则。它提供的检查已经由 TypeScript 提供,无需配置 - TypeScript 只是在这方面做得更好。

在您的 中.eslintrc.js,关闭 TypeScript 文件的规则:

module.exports = {
  root: true,
  extends: '@react-native-community',
  parser: '@typescript-eslint/parser',
  plugins: ['@typescript-eslint'],
  rules: {
    'no-shadow': 'off',
    '@typescript-eslint/no-shadow': ['error'],
  },
  overrides: [
    {
      files: ['*.ts', '*.tsx'],
      rules: {
        'no-undef': 'off',
      },
    },
  ],
};
Run Code Online (Sandbox Code Playgroud)