angular - 即使安装了Typescript 3+版本,Typescript 3+功能也不起作用

标签 angular typescript visual-studio-code compiler-errors tsconfig

我已经在全局范围内安装了 typescript 3.7.3,并且Visual Code正在使用 typescript 版本3.7.3,但我似乎无法访问 typescript 3+功能。例如,当尝试声明类型为“unknown”的变量时,出现编译错误:“找不到名称“unknown”。即使在智能方面它似乎可以作为建议。如何解决此问题?

enter image description here

我的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
 }
}

最佳答案

一个TypeScript版本也可能已安装到node-modules文件夹中。
tsc -v正在报告全局安装的版本。 Visual Studio Code也将拥有它自己的TypeScript编译器版本。

/node-modules/typescript/package.json中 checkin 将使用的TypeScript的实际{ "version": "X.X.X" }

您的项目package.json文件将定义:

"devDependencies": {
    ...
    "typescript": "X.X.X" <- update this.
  }

关于angular - 即使安装了Typescript 3+版本,Typescript 3+功能也不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59831245/

相关文章:

regex - Visual Studio Code - 删除包含条件的行

visual-studio-code - 如何在 Visual Studio Code 中重新映射默认的 CTRL+f(查找),以便我可以像在 unix/linux 中那样使用 CTRL+f?

gulp - Angular2 ng如果不在部署环境中工作

angular - 从另一个组件 Angular 获取值 4

TypeScript 泛型和函数参数

typescript - 如何使用 Props (ReactNative + Typescript) 修复这个错误

angular - 是否可以在没有 npm 的情况下使用嵌入在 JSF 中的 Primeng、Angular2?

javascript - 如何减少对现有 Angular 5 元素的添加

javascript - 限制 Typescript 对象实例化的属性

css - 颜色值突出显示