Tomas Marik
Tomas Marik

Reputation: 4093

Angular 2: Two different types with this name exist

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.

Upvotes: 14

Views: 9993

Answers (3)

Vinit Divekar
Vinit Divekar

Reputation: 918

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

Upvotes: 5

FiringBlanks
FiringBlanks

Reputation: 2084

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.

Upvotes: 6

Tomas Marik
Tomas Marik

Reputation: 4093

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.

Upvotes: 8

Related Questions