rxjs/Subject.d.ts error : Class 'Subject<T>' incorrectly extends base class 'Observable<T>'

Related searches

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 // 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
    

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

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

And in Observable.ts it is defined as below-

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

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

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

  2. I read through this github thread

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

Edit1: 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"
  }
}

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

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

"typescript": "2.3.4"

do npm install

update(06/29/2017):-

As per the comments typescript "2.4.0" working.

Class 'Subject<T>' incorrectly extends base class 'Observable<T , d.ts:16:22 TS2415: Class 'Subject<T>' incorrectly extends base class 'Observable <T>'. Types of property 'lift� rxjs class subject t incorrectly extends base class observable t (12) Add "noStrictGenericChecks": true in tsconfig.json file under "compilerOptions" node as shown in below image & build application. I have faced same error after adding this error resolved.

An admitted band-aid approach is to add the following to your tsconfig.json file until the RxJS folks decide what they want to do about the error when using TypeScript 2.4.1 :

"compilerOptions": {

    "skipLibCheck": true,

 }

RXJS with Angular error � Issue #17800 � angular/angular � GitHub, 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>'. Class 'B' incorrectly extends base class 'A' (two private methods , Since Typescript sits on top of Javscript, and Javascript does not allow inherited classes to have different private implementations for a function **Build:Class 'Subject<T>' incorrectly extends base class 'Observable<T>** . I have installed TypeScript 2.4.1 and downloaded

rxjs/Subject.d.ts error : Class 'Subject<T , Class EndlessReplaySubject<T> This is pretty hacky, but so far I'd found no better way of having Subjects that do no close on multicasted and does not closes observers on errors (thus allowing to continuously dispatch them). Defined in /Users/briankimball/Projects/GitHub/taurus/node_modules/rxjs/Subject .d.ts:18� RxJS version: 5.4.1 Code to reproduce: Save this line this to a TypeScript file (test.ts): import {Subject} from 'rxjs/Subject'; Then compile: tsc test.ts Expected behavior: No errors Actual behavior: Compilation error: node_modules/rxjs

You can temporarily work around the issue by using Module Augmentation

The following code resolved the issue for me. Once RxJS has a stable release that does not exhibit this issue, it should be removed.

// augmentations.ts
import {Operator} from 'rxjs/Operator';
import {Observable} from 'rxjs/Observable';

// TODO: Remove this when a stable release of RxJS without the bug is available.
declare module 'rxjs/Subject' {
  interface Subject<T> {
    lift<R>(operator: Operator<T, R>): Observable<R>;
  }
}

While it is perhaps ironic that RxJS itself makes such heavy use of this technique to describe its own shape, it is actually generally applicable to an array of problems.

While there are certainly limits and rough edges, part of what makes this technique powerful is that we can use it to enhance existing declarations making them more type safe without forking and maintain the entire file.

EndlessReplaySubject, npm start // fall� con error abajo- node_modules/rxjs/Subject.d.ts(16,22): error TS2415: Class 'Subject<T>' incorrectly extends base class 'Observable<T>'. Dismiss Join GitHub today. GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.

"dependencies": {
"@angular/animations": "^4.3.1",
"@angular/common": "^4.3.1",
"@angular/compiler": "^4.3.1",
"@angular/compiler-cli": "^4.3.1",
"@angular/core": "^4.3.1",
"@angular/forms": "^4.3.1",
"@angular/http": "^4.3.1",
"@angular/platform-browser": "^4.3.1",
"@angular/platform-browser-dynamic": "^4.3.1",
"@angular/platform-server": "^4.3.1",
"@angular/router": "^4.3.1",
"core-js": "^2.4.1",
"rxjs": "^5.4.2",
"ts-helpers": "^1.1.1",
"zone.js": "^0.7.2"
},
"devDependencies": {
"@angular/compiler-cli": "^2.3.1",
"@types/jasmine": "2.5.38",
"@types/node": "^6.0.42",
"angular-cli": "1.0.0-beta.28.3",
"codelyzer": "~2.0.0-beta.1",
"jasmine-core": "2.5.2",
"jasmine-spec-reporter": "2.5.0",
"karma": "1.2.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.0.2",
"karma-remap-istanbul": "^0.2.1",
"protractor": "~4.0.13",
"ts-node": "1.2.1",
"tslint": "^4.3.0",
"typescript": "^2.3.4",
"typings": "^1.3.2"
}

in package.json "rxjs": "^5.4.2", and "typescript": "^2.3.4", then npm install and ng serve its working.

angular — error de rxjs/Subject.d.ts: la clase 'Subject <T>' extiende , @DanielRosenwasser The problem is that they've been trying to use Subjects in a way that is fundamentally type-unsafe.I don't know if anything's changed in the year since that discussion happened, but in terms of the actual JS they want a Subject<T>, when transformed by an operator that takes Ts and produces Rs, to still produce a Subject (one that forwards all its values to this), instead of

rxjs/Subject.d.ts error:Class 'Subject<T>' incorrectly extends base class 'Observable<T>' Could not use Observable.of in RxJs 6 and Angular 6 English

rxjs/Subject.d.ts error:Class 'Subject<T>' incorrectly extends base class 'Observable<T>' (12)

Dismiss Join GitHub today. GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.

Comments
  • github.com/Microsoft/TypeScript/issues/16593
  • A little clarification
  • This seems to have been fixed in rxjs@5.4.2.
  • "typescript": "^2.3.4" will match 2.4.1 and 2.4 is the version that exposes the problem with RxJS.
  • Replaced typescript version to "2.4.0" worked for me.
  • I second that it has to be exactly "2.3.4" - "^2.3.4" didn't work for me.
  • combination of "typescript": "2.3.0" and "rxjs": "5.4.1" worked for me
  • @Jonnysai sorry, I take back what I said. Project compiled, but I got a runtime error and downgraded to 2.3.4 . More here: stackoverflow.com/a/44556137
  • Thanks for this, it worked. I tried lots of other things but I guess this error is related with wrong packages with wrong version doesn't support each other...
  • I think its not a good idea to disable or suppress All LibCheck.
  • I suggested the same thing on the github issue