【发布时间】:2017-12-01 07:24:49
【问题描述】:
我从this tutorial 中提取了示例模板代码并执行了以下两个步骤以开始使用 -
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 声明如下 -
lift<T, R>(operator: Operator<T, R>): Observable<T>;
在 Observable.ts 中定义如下-
lift<R>(operator: Operator<T, R>): Observable<R> {
注意:- 1. 我是 Angular2 的新手,正在尝试掌握一些东西。
错误可能是由于lift方法的定义不兼容
我读完了这个github thread
如果我需要安装不同版本的 rxjs,请告诉我如何卸载并安装正确的 rxjs。
编辑1: 我在这里回复可能有点晚,但即使在使用 typescript 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"
}
}
【问题讨论】:
标签: angular typescript rxjs