4

I want to keep noImplicitAny for .ts/.tsx files, but disable it for .js files. I don't want to disable the checkJs option because I still want it to check .js files.

Is this possible?

Here's my base tsconfig.json:

{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "moduleResolution": "node",
    "allowJs": true,
    "checkJs": true,
    "noEmit": true,
    "noEmitHelpers": true,
    "strict": true,
    "isolatedModules": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "baseUrl": "./",
    "noImplicitAny": true,
    "noImplicitOverride": true,
    "strictNullChecks": true,
    "useUnknownInCatchVariables": true,
    "resolveJsonModule": false,
    "types": ["node"],
    "experimentalDecorators": true,
    "noErrorTruncation": true,
    "composite": true
  },
  "include": [
    "."
  ],
  "exclude": [
    "./node_modules",
    "./build"
  ]
}
Leo Jiang
  • 24,497
  • 49
  • 154
  • 284
  • 2
    If your .js and .ts files are in a different places, then you could make use of https://stackoverflow.com/questions/61611311/how-to-use-multiple-tsconfig-files-with-conflicting-compiler-options – Murat Karagöz Aug 02 '21 at 06:22

1 Answers1

3

Unfortunately, this is not something you can achieve like that. One way you could achieve that would be to have two tsconfig file.

So basically, the main tsconfig.json would do everything except checkJs and the second one (let's call it tsconfig.typeCheckJs.json) would add the checkJs, notImplicitAny and noEmit.

For example

// tsconfig.json
{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "moduleResolution": "node",
    "allowJs": true,
    "checkJs": false,
    "strict": true,
    "isolatedModules": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "baseUrl": "./",
    "noImplicitAny": true,
    "noImplicitOverride": true,
    "strictNullChecks": true,
    "useUnknownInCatchVariables": true,
    "resolveJsonModule": false,
    "types": ["node"],
    "experimentalDecorators": true,
    "noErrorTruncation": true,
    "composite": true
  },
  "include": [
    "."
  ],
  "exclude": [
    "./node_modules",
    "./build"
  ]
}

and another one

// tsconfig.typeCheckJs.json
{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "moduleResolution": "node",
    "allowJs": true,
    "checkJs": true,
    "noEmit": true,
    "noEmitHelpers": true,
    "strict": true,
    "isolatedModules": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "baseUrl": "./",
    "noImplicitAny": false,
    "noImplicitOverride": true,
    "strictNullChecks": true,
    "useUnknownInCatchVariables": true,
    "resolveJsonModule": false,
    "types": ["node"],
    "experimentalDecorators": true,
    "noErrorTruncation": true,
    "composite": true
  },
  "include": [
    "."
  ],
  "exclude": [
    "./node_modules",
    "./build"
  ]
}

then, you need to update your scripts to something like this:

// package.json
scripts: {
    "build": "./node_modules/.bin/tsc --project tsconfig.typeCheckJs.json && ./node_modules/.bin/tsc"
}

Hope that it is clear, otherwise do not hesitate to ask for clarifications.

Adrien De Peretti
  • 3,342
  • 16
  • 22