rxjs/Subject.d.ts错误:类'Subject< T>'错误地扩展了基类'Observable< T>' [英] rxjs/Subject.d.ts error : Class 'Subject<T>' incorrectly extends base class 'Observable<T>'

查看:120
本文介绍了rxjs/Subject.d.ts错误:类'Subject< T>'错误地扩展了基类'Observable< T>'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从本教程中提取了示例模板代码,并执行了以下两个步骤来获取开始-

I extracted sample template code from this tutorial and did below two steps to get started -

  1. npm install // worked fine and created node_modules folder with all dependencies
  2. npm start //失败,并出现以下错误-

  1. npm install // worked fine and created node_modules folder with all dependencies
  2. npm start // failed with below error-

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中声明如下-

I see that in the subject.d.ts declaration of lift is as below -

 lift<T, R>(operator: Operator<T, R>): Observable<T>;

在Observable.ts中,它的定义如下-

And in Observable.ts it is defined as below-

 lift<R>(operator: Operator<T, R>): Observable<R> {

注意:- 1.我是Angular2的新手,正在尝试掌握一切.

Note:- 1. I am new to Angular2 and trying to get hold of things.

  1. 该错误可能是由于提升方法的定义不兼容

  1. The error might be due to incompatible definitions of lift method

我通读了 github线程

如果我需要安装其他版本的rxjs,请告诉我们如何卸载并安装正确的rxjs.

If I need to install some different version of rxjs then please tell how to uninstall and install the correct rxjs.

我在这里做出回应可能有点晚了,但是即使使用 typescript 2.3.4 rxjs 6 alpha ,我仍然会遇到相同的错误.下面是我的package.json,

I might be a bit late in responding here but I still get the same error even after using typescript 2.3.4 or rxjs 6 alpha. Below is my 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"
  }
}

推荐答案

按照您需要更新打字稿2.3.4或rxjs 6 alpha

As per this you need update typescript 2.3.4 or rxjs 6 alpha

在项目更新打字稿或rxjs版本中进入您的package.json文件. 例子

go the your package.json file in your project update typescript or rxjs version. Example

"typescript": "2.3.4"

执行npm install

更新(2017年6月29日):-

根据评论打字稿"2.4.0"正常工作.

As per the comments typescript "2.4.0" working.

这篇关于rxjs/Subject.d.ts错误:类'Subject&lt; T&gt;'错误地扩展了基类'Observable&lt; T&gt;'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆