how to fix `error 'JSX' is not defined no-undef` after upgrade to typescript 4.4.2

Viewed 1737

I have lots of error error 'x' is not defined no-undef after upgrade to typescript 4.4.2 from typescript 3.8.2. one of example is error 'JSX' is not defined no-undef and I take a deeper look, most of is from declarations.d.ts how can I solve it?

"typescript": "4.4.2"
"@typescript-eslint/eslint-plugin": "4.31.0",
"@typescript-eslint/parser": "4.31.0",
2 Answers

From the typescript-eslint troubleshooting guide:

We strongly recommend that you do not use the no-undef lint rule on TypeScript projects. The checks it provides are already provided by TypeScript without the need for configuration - TypeScript just does this significantly better.

In your .eslintrc.js, turn the rule off for TypeScript files:

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',
      },
    },
  ],
};

This worked for me in my .eslintrc.json

For eslintrc.js refer here

 "overrides": [
    {
      "files": ["*.ts", "*.tsx"],
      "rules": {
        "no-undef": "off"
      }
    }
  ]
Related