[英]Why does VS Code NOT throw "Cannot find module 'typescript'. ts(2307)" when the module is NOT there in js files?
I am using VScode with several react apps.我正在将 VScode 与几个反应应用程序一起使用。 For one of my projects, in the .js files I do not get the "Cannot find module 'typescript'. ts(2307)" alert on
import something from './an/incorrect/path'
lines, where I would expect that ts2307 alert.对于我的一个项目,在 .js 文件中,我在
import something from './an/incorrect/path'
没有收到“找不到模块'typescript'.ts(2307)”警报,我希望ts2307 警报。
However I do get that alert in .ts files that import from incorrect paths.但是,我确实在从错误路径导入的 .ts 文件中收到该警报。
How do I get those alerts to appear as well in .js files?如何让这些警报也出现在 .js 文件中?
I've checked that both of these settings are set to true in VScode settings.json.我检查了这两个设置在 VScode settings.json 中都设置为 true。 You want to change these two settings in VS Code's settings.json:
您想在 VS Code 的 settings.json 中更改这两个设置:
"typescript.validate.enable": true,
"javascript.validate.enable": true,
This is my tsconfig file.这是我的 tsconfig 文件。
{
"compilerOptions": {
"target": "ES5",
"module": "commonjs",
"lib": ["es2017", "dom"],
"allowJs": true,
"jsx": "react",
"noImplicitAny": false,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"skipLibCheck": true,
"outDir": "lib"
},
"include": ["./**/*"]
}
I just found the answer, right after I considered that typescript checking might be entirely disabled for .js files.我刚刚找到了答案,就在我认为可能对 .js 文件完全禁用打字稿检查之后。 Then I found I had to add
"checkJs": true
to the compilerOptions in tsconfig.json.然后我发现我必须在 tsconfig.json 中的 compilerOptions 中添加
"checkJs": true
。
ts2307 are now correctly shown when trying to import from incorrect file paths.尝试从不正确的文件路径导入时,现在可以正确显示 ts2307。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.