【发布时间】:2020-05-06 22:22:37
【问题描述】:
我已全局安装了 typescript 3.7.3,Visual Code 使用的是 Typescript 3.7.3 版,但我似乎无法访问 Typescript 3+ 功能。例如,当尝试声明类型为“未知”的变量时,我收到一个编译错误:“找不到名称‘未知’。尽管它似乎可以作为智能建议使用。我该如何解决这个问题?
我的 tscongif.json 是:
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"emitDecoratorMetadata": true, // Needed for Stackblitz
"experimentalDecorators": true,
"module": "esnext",
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2018",
"dom"
]
},
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true
}
}
【问题讨论】:
-
如果您通过命令行构建,您是否也会看到此错误?还是仅在 Visual Studio Code 中?
-
它只在 VS 代码中。并且智能感知知道类型并提供自动完成,但是一旦添加它就会被标记为红色,并带有错误代码,如图所示。
标签: angular typescript visual-studio-code compiler-errors tsconfig