1

Suppose I start with an empty directory and execute the following command to bootstrap a fresh project with a minimal setup to reproduce this:

npm install --save-dev typescript eslint eslint-config-airbnb-typescript

After that I open the project in vscode, and add .eslintrc.cjs with the following content:

/* eslint-env node */
const eslintConfig = require("eslint-config-airbnb-typescript/lib/shared");
// does not matter what I do with eslintConfig

Here on a 2nd line vscode will underline the beginning of require argument to denote a warning and if you hover mouse pointer on it, you will get:

Could not find a declaration file for module 'eslint-config-airbnb-typescript/lib/shared'. '/Users/user/projects/ts-error-in-js-file/node_modules/eslint-config-airbnb-typescript/lib/shared.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/eslint-config-airbnb-typescript` if it exists or add a new declaration (.d.ts) file containing `declare module 'eslint-config-airbnb-typescript/lib/shared';`ts(7016)

Visually it looks like this:

ts-related warning

Notice that ts(7016) is a TypeScript compiler error. But why is this inspection applied to js-file?

My first thought is that I probably need to exclude the file from tsconfig, so I generate one with npx tsc --init and explicitly exclude this file. I can make sure that my exclusion worked out by trying to execute npx tsc and observing no complains on that file. Unfortunately, this nasty little warning in vscode does not disappear. After googling the problem I found this similar old question and answers to it suggest to adjust vscode settings as follows: "javascript.validate.enable": false. This options indeed removes the warning, but it will also disable TypeScript-related inspections on ANY js-files, which is not what you want in case when you have a mixed codebase with "allowJs": true and "checkJs": true in your tsconfig.

Is there a proper way to disable such ts-inspections for js-files which are not-included in the context with tsconfig?

2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.