Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

276
Views
Type '() => Observable<any>' is not assignable to type '() => Observable<any>'

I'm making an ionic 2 app using typescript and after upgrading the local typescript installation to version 2.2.1 from version 2.1.0 I have started receiving this error:

Type '() => Observable' is not assignable to type '() => Observable'. Two different types with this name exist, but they are unrelated. Type 'Observable' is not assignable to type 'Observable'. Two different types with this name exist, but they are unrelated.

This error repeats for each of the following lines

L28:  this.onDisconnect = Network.onDisconnect
L29:  this.onchange = Network.onchange
L30:  this.ontypechange = Network.ontypechange

Network is a class imported from ionic-native its onDisconnect, onchange and ontypechange methods are defined as follow:

static onDisconnect(): Observable<any>;
static onchange(): Observable<any>;
static ontypechange(): Observable<any>;

I have onDisconnect, onchange, and ontypechange as public properties of a custom class (@Injectable() class) called "Network" and I have defined them as follows:

L15:  public onDisconnect: ()=>Observable<any>
L16:  public ontypechange: ()=>Observable<any>
L17:  public onchange: ()=>Observable<any>

I have three questions?

First: Would someone help me understand what the error really means in typescript and why it occurs as such in my code.

Second: While I do know I could just extend the class, I do not want to do it. So I am asking, does the difference in declaring my methods as public while the ones in the class are static cause this problem?

Third: what's the difference of these two kinds of defining a property on a class?

EDIT:

I just realized that I had previously tried extending the Network class and this failed due to the static declaration

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

You have two different versions of rxjs lurking in your node_modules tree, and TS does not know that they are the "same".

The first thing to try would be to clear your entire node_modules directory, flush the npm cache, and redo npm install.

If that does not solve the problem, the underlying issue is likely to be that different dependencies have specified rxjs versions which are incompatible, forcing npm to bring in a separate version of rxjs for one or more of them (which it will place in the node_modules directory under some module). You will see a structure such as

node_modules
  dependencyA
  rxjs
  dependencyB
    node_modules
      rxjs

If this is what is happening, then you will have no option but to track down the offending version requirement. For instance, the top level package.json may have rxjs: "^5.2.0", whereas dependencyB/package.json may have rxjs: "5.0.0".

over 4 years ago · Santiago Trujillo Report

0

This worked for me:

Changing import { Observable } from rxjs/observable to import { Observable } from rxjs;

over 4 years ago · Santiago Trujillo Report

0

I was getting a similar error as a result of incompatibility between RxJS and Ngrx v7 in a certain version. Downgrading RxJS to ~6.4.0 helped. I ran yarn add rxjs@~6.4.0 worked for me and the error was resolved.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!