我最近更新了 typescript、angular,基本上更新了我项目中的每个库。在我进行此更新之前,问题不存在。从命令行我确保我的代码构建时没有错误或警告。但是,当我在 Visual Studio Code 中打开项目并对文件进行更改时,它开始将内容突出显示为错误。
它在顶部突出显示我的导入,说找不到模块“angular2/core”。
和我的@Components
、@Output
和@Input
说对装饰器的实验性支持是一项在未来版本中可能会发生变化的功能。指定“--experimentalDecorators”以删除此警告。
它还突出显示了我在 .d.ts
文件中声明的一些 Window
属性。
然而这是我的 tsconfig.json:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"inlineSourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": true,
"noImplicitReturns": true,
"pretty": true
},
"exclude": [ "node_modules" ]
}
似乎当我更改文件时,VSCode 正在构建我刚刚更改的单个文件,而没有使用我的 tsconfig。如果我从命令行构建,我会得到零错误或警告。如果我按 Ctrl+Shift+B 在 VSCode 中运行构建,那么所有错误都会消失。这是我的 tasks.json:
{
"version": "0.1.0",
"command": "tsc",
"isShellCommand": true,
"showOutput": "silent",
"args": ["-p", "."],
"problemMatcher": "$tsc"
}
我如何让 VSCode 使用整个项目而不只是一个文件来查找错误和警告?
VS代码0.10.8 typescript 1.8.7 Linux 薄荷 17.3 x64
最佳答案
原来 VSCode 带有它自己的 typescript 实例,通过更新我超越了内置的版本。
I was notified on github您可以通过将其添加到您的用户或工作区设置来指定要使用的 typescript :
"typescript.tsdk": "node_modules/typescript/lib/"
这解决了我的问题。
关于typescript - VSCode 忽略 tsconfig.json 并编译生成不正确错误的单个文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35778924/