[英]Missing TypeScript type definitions for the @Angular packages in Angular 2
现在我已将我的应用程序更新到Angular2 v2.0.0-rc.1,当我的应用程序被捆绑在webpack中时,我再次看到TypeScript编译错误/警告消息。 这些消息出现在我从TypeScript源文件中引用的任何@angular
包中,例如:
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'.
使用Angular2的早期beta版本,我通过在app.ts
文件的顶部包含类似这样的内容来解决Promise
和Map
等类似的消息问题。
///<reference path="node_modules/angular2/typings/browser.d.ts"/>
是否有@angular
Angular2包的d.ts
文件,我可以参考来修复问题? 到目前为止, typings
系统似乎没有任何可用的东西:
MFO-Mac:angular2-oauth2 mfo$ typings search '@angular'
No results found for search
现在我将我的TypeScript tsconfig.json
文件配置为以ES6为目标。 但是,如果我将其更改为目标ES5,我不会得到这些@angular
错误,但我会为常见的ES6类(如Promise
, Set
和Map
获取错误。 这是我为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": [
]
}
我怀疑在node_modules/@angular
中有文件可以在tsconfig.json
文件的definitions
部分tsconfig.json
,但我目前还不知道TypeScript typedef文件是如何工作的。
如果还有另一种方法来解决这个问题,我当然也会对此持开放态度。
似乎TypeScript编译器足够智能,如果你告诉它你正在使用Node / NPM样式模块,那么就可以自己定义文件定义文件。
通过将"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": []
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.