angular - 在 Visual Studio 2015 中从类型转换为@types

标签 angular typescript visual-studio-2015 typescript-typings typescript2.0

摆脱 typings 配置并改为添加 @types 在编译项目时产生了一系列错误。显然 @types/core-js 可以被 typescript 编译器和 VS IntelliSense 看到。

这里是许多错误之一的示例

Severity    Code    Description Project File    Line    Suppression State
Error   TS2304  Cannot find name 'Set'. TypeScript Virtual Projects C:\Projects\Cool\Project\node_modules\@angular\common\src\directives\ng_class.d.ts  46  Active

Severity    Code    Description Project File    Line    Suppression State
Error   TS2304  Cannot find name 'Promise'. TypeScript Virtual Projects C:\Projects\Cool\Project\node_modules\@angular\common\src\pipes\async_pipe.d.ts 44  Active

SetPromise由core-js定义

按照package.json配置

"name": "Cool",
  "private": true,
  "scripts": {
    "tsc": "tsc",
    "tsc:w": "tsc -w"
  },
  "dependencies": {
    "@angular/common": "~2.1.1",
    "@angular/compiler": "~2.1.1",
    "@angular/core": "~2.1.1",
    "@angular/forms": "~2.1.1",
    "@angular/http": "~2.1.1",
    "@angular/platform-browser": "~2.1.1",
    "@angular/platform-browser-dynamic": "~2.1.1",
    "@angular/router": "~3.1.1",
    "@angular/upgrade": "~2.1.1",
    "@types/core-js": "^0.9.34",
    "@types/mcustomscrollbar": "^2.8.30",
    "angular-in-memory-web-api": "~0.1.13",
    "animate.css": "3.5.2",
    "bootstrap": "~3.3.5",
    "core-js": "^2.4.1",
    "es6-promise": "^4.0.3",
    "es6-shim": "^0.35.1",
    "font-awesome": "^4.6.3",
    "jquery": "2.1.4",
    "malihu-custom-scrollbar-plugin": "~3.1.5",
    "material-design-iconic-font": "~2.2.0",
    "moment": "^2.15.1",
    "reflect-metadata": "^0.1.8",
    "rxjs": "5.0.0-beta.12",
    "systemjs": "0.19.39",
    "zone.js": "^0.6.25"
  },
  "devDependencies": {        
    "@types/node": "^6.0.45",
    "typescript": "^2.0.6"
  }
}

这是tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "noImplicitAny": false,
    "noEmitOnError": true,
    "removeComments": true,
    "sourceMap": true,
    "module": "commonjs",
    "moduleResolution": "node",
    "outDir": "./Scripts/app",
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "allowSyntheticDefaultImports": true,
    "jsx": "react",
    "typeRoots": [
      "./node_modules/@types"
    ]            
  },
  "exclude": [

  ],
  "files": [
    "./Scripts/src/main.ts" 
  ],
  "compileOnSave": true
}

感谢帮助!!!

最佳答案

原来我有tsc 1.8。通过安装 tsc 2.0.x,所有编译错误都消失了。谢谢。

关于angular - 在 Visual Studio 2015 中从类型转换为@types,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40274347/

相关文章:

javascript - 模型驱动的表单 - IE11 上的输入占位符问题

css - 文本区域的模板驱动表单验证

typescript - 如何将异步函数添加到类型 def 文件?

javascript - ionic 2/Angular 2 - 无法将数据从 Google Maps InfoWindow 传递到页面

javascript - 动态添加 span 标签到 <ng-content></ng-content> 内的链接

javascript - 如何获取 Angular 列表 [Object] 值

typescript - 'typeRoots' 无法在项目中找到 d.ts 声明文件

c++ - 设置一个项目,该项目将使用和不使用预编译头文件进行编译

.net - 如何在VS 2015中打开性能监视器?

oracle - 使用 Oracle 数据库中的数据进行 Visual Studio 2015 Web 测试