Turn off VSCode Typescript Errors for .JS / .JSX files & keep them for .TS / .TSX files?

Viewed 1620

I am trying to use typescript as well as plain javascript. So some files are javascript files (.js), while others are typescript files (.ts). This works.

However, my eslint in VSCode gives me Typescript Errors & Warnings, even in the plain javascript files.

Can I turn those off for the .js files, but keep them turned on whenever the file is a .ts / .tsx ?

My eslint & typescript configs are just Vercels official typescript example.

.eslintignore :

**/node_modules/*
**/out/*
**/.next/*

.eslintrc.json :

{
  "parser": "@typescript-eslint/parser",
  "plugins": ["@typescript-eslint"],
  "extends": [
    "eslint:recommended",
    "plugin:react/recommended",
    "plugin:@typescript-eslint/recommended",
    // Uncomment the following lines to enable eslint-config-prettier
    // Is not enabled right now to avoid issues with the Next.js repo
    "prettier",
    "prettier/@typescript-eslint"
  ],
  "env": {
    "es6": true,
    "browser": true,
    "jest": true,
    "node": true
  },
  "settings": {
    "react": {
      "version": "detect"
    }
  },
  "rules": {
    "react/react-in-jsx-scope": 0,
    "react/display-name": 0,
    "react/prop-types": 0,
    "@typescript-eslint/explicit-function-return-type": 0,
    "@typescript-eslint/explicit-member-accessibility": 0,
    "@typescript-eslint/indent": 0,
    "@typescript-eslint/member-delimiter-style": 0,
    "@typescript-eslint/no-explicit-any": 0,
    "@typescript-eslint/no-var-requires": 0,
    "@typescript-eslint/no-use-before-define": 0,
    "@typescript-eslint/no-unused-vars": [
      2,
      {
        "argsIgnorePattern": "^_"
      }
    ],
    "no-console": [
      2,
      {
        "allow": ["warn", "error"]
      }
    ]
  }
}

tsconfig.json :

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": false,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve"
  },
  "exclude": ["node_modules", ".next", "out", "**/*.js", "**/*.jsx"],
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"] 
}

enter image description here

1 Answers

In your .eslintignore file add this line

**/*.js

By which eslint will not lint any *.js files.

Related