Angular 打字稿3+;即使Typescript 3+;版本已安装
我已经在全球安装了typescript 3.7.3,可视化代码正在使用typescript版本3.7.3,但我似乎无法访问typescript 3+功能。例如,当试图声明一个类型为“unknown”的变量时,我得到一个编译错误:“找不到名称‘unknown’。即使它在intellisence中似乎可以作为建议使用。我如何解决这个问题?” 我的tscongif.json是:Angular 打字稿3+;即使Typescript 3+;版本已安装,angular,typescript,visual-studio-code,compiler-errors,tsconfig,Angular,Typescript,Visual Studio Code,Compiler Errors,Tsconfig,我已经在全球安装了typescript 3.7.3,可视化代码正在使用typescript版本3.7.3,但我似乎无法访问typescript 3+功能。例如,当试图声明一个类型为“unknown”的变量时,我得到一个编译错误:“找不到名称‘unknown’。即使它在intellisence中似乎可以作为建议使用。我如何解决这个问题?” 我的tscongif.json是: { "compileOnSave": false, "compilerOptions": { "baseUrl"
{
"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
}
}
您的
节点模块
文件夹中可能还安装了一个版本的TypeScript
tsc-v
正在报告全局安装的版本。Visual Studio代码还将拥有自己版本的TypeScript编译器
签入/node modules/typescript/package.json
,查看将使用的typescript的实际{“version”:“X.X.X”}
您的项目package.json
文件将定义:
"devDependencies": {
...
"typescript": "X.X.X" <- update this.
}
“开发依赖性”:{
...
“typescript”:“X.X.X”谢谢,我已经检查过了。我现在已经全局安装了3.4.3版,并设置了VS代码来使用它。json我有“typescript”:“^3.4.3”。我仍然得到:“找不到名称‘未知’”“。还有什么可以超越它的吗?如果我理解正确,有一个VS code使用的typescript语言服务,它指向您提到的node_模块中的typescript文件:在settings.json中,我有“typescript.tsdk”:“node_模块\\typescript\\lib”如果通过命令行生成,是否也会看到此错误?还是仅在Visual Studio代码中?它仅在VS代码中。intellisense知道类型并提供自动完成功能,但一旦添加,它将被标记为红色,并带有错误代码,如图所示。