繁体   English   中英

当 js 文件中不存在模块时,为什么 VS Code 不会抛出“找不到模块 'typescript'.ts(2307)”?

[英]Why does VS Code NOT throw "Cannot find module 'typescript'. ts(2307)" when the module is NOT there in js files?

我正在将 VScode 与几个反应应用程序一起使用。 对于我的一个项目,在 .js 文件中,我在import something from './an/incorrect/path'没有收到“找不到模块'typescript'.ts(2307)”警报,我希望ts2307 警报。

但是,我确实在从错误路径导入的 .ts 文件中收到该警报。

如何让这些警报也出现在 .js 文件中?

我检查了这两个设置在 VScode settings.json 中都设置为 true。 您想在 VS Code 的 settings.json 中更改这两个设置:

"typescript.validate.enable": true,
"javascript.validate.enable": true,

这是我的 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": ["./**/*"]
}

我刚刚找到了答案,就在我认为可能对 .js 文件完全禁用打字稿检查之后。 然后我发现我必须在 tsconfig.json 中的 compilerOptions 中添加"checkJs": true

尝试从不正确的文件路径导入时,现在可以正确显示 ts2307。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM