我从本教程中提取了示例模板代码,并按照以下两个步骤进行了入门-
npm install // worked fine and created node_modules folder with all dependencies
npm start
//失败,并出现以下错误-node_modules/rxjs/Subject.d.ts(16,22): error TS2415: Class 'Subject<T>' incorrectly extends base class 'Observable<T>'. Types of property 'lift' are incompatible. Type '<T, R>(operator: Operator<T, R>) => Observable<T>' is not assignable to type '<R>(operator: Operator<T, R>) => Observable<R>'. Type 'Observable<T>' is not assignable to type 'Observable<R>'. Type 'T' is not assignable to type 'R'. npm ERR! code ELIFECYCLE npm ERR! errno 2
我看到在抬升的subject.d.ts声明如下-
lift<T, R>(operator: Operator<T, R>): Observable<T>;
在Observable.ts中,它的定义如下:
lift<R>(operator: Operator<T, R>): Observable<R> {
注意:1.我是Angular2的新手,正在尝试掌握一切。
该错误可能是由于提升方法的定义不兼容
我阅读了这个github线程
如果我需要安装其他版本的rxjs,请说明如何卸载和安装正确的rxjs。
Edit1: 我在这里响应可能有点晚,但是即使使用打字稿2.3.4或rxjs 6 alpha,我仍然会遇到相同的错误。以下是我的package.json,
{
"name": "angular-quickstart",
"version": "1.0.0",
"scripts": {
"start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ",
"lite": "lite-server",
"postinstall": "typings install",
"tsc": "tsc",
"tsc:w": "tsc -w",
"typings": "typings"
},
"license": "ISC",
"dependencies": {
"@angular/common": "2.0.0",
"@angular/compiler": "2.0.0",
"@angular/core": "2.0.0",
"@angular/forms": "2.0.0",
"@angular/http": "2.0.0",
"@angular/platform-browser": "2.0.0",
"@angular/platform-browser-dynamic": "2.0.0",
"@angular/router": "3.0.0",
"@angular/upgrade": "2.0.0",
"core-js": "^2.4.1",
"reflect-metadata": "^0.1.3",
"rxjs": "6.0.0-alpha.0",
"systemjs": "0.19.27",
"zone.js": "^0.6.23",
"angular2-in-memory-web-api": "0.0.20",
"bootstrap": "^3.3.6"
},
"devDependencies": {
"concurrently": "^2.2.0",
"lite-server": "^2.2.2",
"typescript": "2.3.4",
"typings": "^1.3.2"
}
}