rxjs/Subject.d.ts 错误:类 'Subject<T>'错误地扩展了基类“Observable&lt;T&gt;" [英] rxjs/Subject.d.ts error : Class &#39;Subject&lt;T&gt;&#39; incorrectly extends base class &#39;Observable&lt;T&gt;&#39;

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

问题描述

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

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

  1. npm install//工作正常并创建了包含所有依赖项的 node_modules 文件夹
  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中看到lift的声明如下-

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.

编辑 1:我在这里回复可能有点晚了,但即使在使用 typescript 2.3.4rxjs 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"
  }
}

推荐答案

根据 this 你需要更新 typescript 2.3.4 或 rxjs 6 alpha

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

去你的项目中的 package.json 文件更新打字稿或 rxjs 版本.示例

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

"typescript": "2.3.4"

do npm install

更新(06/29/2017):-

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

As per the comments typescript "2.4.0" working.

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

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