缺少Angular 2中@Angular包的TypeScript类型定义

Mic*_*ryl 4 javascript angularjs typescript webpack angular

现在我已将我的应用程序更新到Angular2 v2.0.0-rc.1,当我的应用程序被捆绑在webpack中时,我再次看到TypeScript编译错误/警告消息.@angular我从TypeScript源文件中引用的任何包都会出现这些消息,例如:

ERROR in ./src/app/app.ts
(1,34): error TS2307: Cannot find module '@angular/core'.

ERROR in ./src/app/app.ts
(3,76): error TS2307: Cannot find module '@angular/common'.

ERROR in ./src/app/app.ts
(4,30): error TS2307: Cannot find module '@angular/http'.
Run Code Online (Sandbox Code Playgroud)

使用Angular2的早期beta版本,我遇到类似的类似的消息问题,PromiseMap在我的app.ts文件顶部包含类似的东西.

///<reference path="node_modules/angular2/typings/browser.d.ts"/>
Run Code Online (Sandbox Code Playgroud)

我可以参考Angular2包的d.ts文件@angular来解决问题吗?到目前为止,似乎typings系统没有任何可用的东西:

MFO-Mac:angular2-oauth2 mfo$ typings search '@angular'
No results found for search
Run Code Online (Sandbox Code Playgroud)

现在我将我的TypeScript tsconfig.json文件配置为以ES6为目标.但是,如果我改变它的目标,而不是ES5,我不明白这些@angular错误,但我反而得到普遍ES6类错误,如Promise,SetMap.这是我为ES6配置的文件:

{
  "version": "1.6.2",
  "compilerOptions": {
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es6",
    "module": "commonjs",
    "removeComments": true,
    "sourceMap": true
  },
  "exclude": [
    "node_modules",
    "bower_components",
    "bootstrap"
  ],
  "files": [],
  "definitions": [
  ]
}
Run Code Online (Sandbox Code Playgroud)

我怀疑有些文件node_modules/@angular可以列在文件的definitions部分tsconfig.json,但我目前还不知道TypeScript typedef文件是如何工作的.

如果还有另一种方法来解决这个问题,我当然也会对此持开放态度.

Mic*_*ryl 5

如果你告诉它你正在使用Node/NPM样式模块,那么TypeScript编译器似乎足够智能,可以自己定义文件定义文件本身.

通过添加"moduleResolution": "node",到我的tsconfig.json文件,问题消息消失,应用程序继续按预期工作.

这是我的新文件(新增加的是第4行):

{
  "version": "1.6.2",
  "compilerOptions": {
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es6",
    "module": "commonjs",
    "removeComments": true,
    "sourceMap": true
  },
  "exclude": [
    "node_modules",
    "bower_components",
    "bootstrap"
  ],
  "files": [],
  "definitions": []
}
Run Code Online (Sandbox Code Playgroud)