Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2: Two different types with this name exist

Tags:

angular

In my Angular 2 app, I have following code:

import { Observable } from 'rxjs/Rx';
import { Subscription } from '@angular-cli/ast-tools/node_modules/rxjs/Rx';
...
private broadcastDataSubject: BehaviorSubject<Event>;
...
let sub: Subscription = this.broadcastDataSubject.asObservable().subject(event).subscribe(() => this.bla());

Problem is in the last row, code will not complile because of:

"Type 'Subscription' is not assignable to type 'Subscription'. Two different types with this name exist, but they are unrelated."

I have same code in my second project and it runs without problem.

like image 960
Tomas Marik Avatar asked Apr 10 '17 19:04

Tomas Marik


3 Answers

The problem was that I had 2 same imports:

import { Subscription } from '@angular-cli/ast-tools/node_modules/rxjs/Rx';

One in the component and one in service.

like image 125
Tomas Marik Avatar answered Nov 17 '22 09:11

Tomas Marik


I was having the same issue until I saw that I was importing my Observable from:

import { Observable } from '@firebase/util';

I changed it to:

import { Observable } from 'rxjs/Observable';

and it was working fine.

like image 21
FiringBlanks Avatar answered Nov 17 '22 07:11

FiringBlanks


I got this error when I misspelt Observable. In the import I wrote:

import { Observable } from 'rxjs/observable';

where as it should be

import { Observable } from 'rxjs/Observable';

P.S. this was for the version 5.2.11

like image 5
Vinit Divekar Avatar answered Nov 17 '22 08:11

Vinit Divekar