-
Notifications
You must be signed in to change notification settings - Fork 12.8k
checkJS has no effect when allowJS is not enabled in the tsconfig.json #21435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
And thus For the OP, the original design for I believe what you are requesting here is a new mode where you can tell the compiler what files need to be transpiled, and what files only need to be checked only and do not bother moving them to the output... I think using Currently the two modes available are, transpile all files, including For a check-only context, you need to create a new project. this can be done by simply adding a new tsconfig.json file that inherits the configurations from your main one and adds .js files, and I would like to get more context on what is it that you were trying to accomplish, and how common is this hybrid projects (with .ts and .js files) that require checking but not transpiling the .js files. |
In VS Code we have a folder https://github.com/Microsoft/vscode/tree/master/build that contains the gulp build scripts and some helpers, these are all .js files. We do not want to have a build/transpile step for the build scripts, for this reason we kept them as .js files. This folder also happens to contain some build related code like our packager which is implemented in Typescript. The scenario is that we would like to get type checking for the .js files and I was hoping to enable type checking with minimal changes to the project configuration. Having to define another project context/tsconfig.json should work, but I was hoping for a simpler way to achieve this. |
I was able to get the desired setup using two separate tsconfig.json files as @mhegazy suggested. While this works it looks a bit contrived. tsconfig.json - used by the language service {
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"noImplicitAny": false,
"removeComments": false,
"preserveConstEnums": true,
"sourceMap": false,
"experimentalDecorators": true,
"newLine": "LF",
"allowJs": true,
"checkJs": true
},
"exclude": [
"node_modules/**"
]
} tsconfig.build.json - used by the compiler/build {
"extends": "./tsconfig.json",
"compilerOptions": {
"allowJs": false,
"checkJs": false
}
} |
Fixed at #40275 |
Background we want to enable checkJS in a folder that contains JS code inside the vscode repository microsoft/vscode#41953. This folder is a hybrid TS and JS folder and would be a good application for enabling checkJS.
However, setting
checkJS
to true without settingallowJS
to true in atsconfig.json
file has no effect:checking happens when both attributes are true:

no checking when allowJS is set to false:

Defining allowJS to true for this folder has the side effect that the compiler wants to emit transpiled JS files and would overwrite the existing JS files. Having to change the project structure to use an output folder should not be required when enabling checkJS and I haven´t found a way to specify
noEmit
only for JS files.Therefore, it must be possible to check JS files using the project context defined in the tsconfig.json without that the JS files are transpiled and code is emitted.
We have tried to work around this by adding
//@ts-check
comments to the JS files. However, this has the side effect that the project context defined in the tsconfig.json is ignored. This results in nasty issues that a typings file is used from the global type cache but not from a typings file that is included in a child folder of the tsconfig.json folder. This results in false errors.Related #16738 but this issue proposes to automatically enable allowJS when checkJS is enabled. The issue here is about enabling checkJS without transpiling the JS files and generating code.
The text was updated successfully, but these errors were encountered: