Typescript: Type 'Subscription' is not assignable to type 'Subscription'

Created on 13 Apr 2017  ·  12Comments  ·  Source: microsoft/TypeScript

TypeScript Version:

2.2.2

Code:

private ts:Subscription
this.ts = Keyboard.onKeyboardShow().subscribe(e => this.onShow(e));

Expected behavior:

Should work with no errors

Actual behavior:
Throws error

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

Notes:

This just started happening after I upgraded Angular to 2.2.2 and rxjs to 5.1.1

External

Most helpful comment

I suddenly had the exact same problem in the code that had worked successfully before.
I just deleted import:
import {Subscription} from 'rxjs/Subscription';
re-imported and the error did not appear

All 12 comments

Please provide a self-contained repro. We don't maintain the Angular or rxjs definition files, nor can we see your code

+1

same to me

@marek1 and @rodriguesgm please provide a self-contained repro we can use to investigate, otherwise, i am afraid this issue is not actionable for us.

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

i have same problem with videogular2 im trying to getisHidden status
this.subscriptions.push(this.hidden.isHidden.subscribe(this.onHideControls.bind(this)));

error Type 'Subscription' is not assignable to type 'Subscription'
Property '_parent' is missing in type 'Subsciption'

I solved this problem by downgrading rxjs to 5.0.1

I suddenly had the exact same problem in the code that had worked successfully before.
I just deleted import:
import {Subscription} from 'rxjs/Subscription';
re-imported and the error did not appear

Thanks @GonzoBard this was also my issue, following an upgrade from Angular 5.2 to Angular 6. I had the following import:

import { Observable, Subscription } from 'rxjs/Rx';

I had to delete this whole line, save the .ts file, re-add the line and save again, and this fixed the errors (deleting only Subscription from the import didn't work - I had to remove and re-add the whole line).

In _another_ case of this issue I had to replace this:

import { Subscription } from 'rxjs/Subscription';

with:

import { Subscription } from 'rxjs';

I had already followed the Angular upgrade step to 'Remove deprecated RxJS 6 features', by running the following:

npm install -g rxjs-tslint
rxjs-5-to-6-migrate -p src/tsconfig.app.json

Does anyone have an explanation for why these actions are required?

Seems like angular v8 is guilty in that error as well. Downgrading rxjs to "rxjs": "6.4.0" helped me.

Had the same problem and found this solution on stackoverflow:

So, I'm not sure why this worked but I'm answering my own question just in case someone else runs into this issue.

I uninstalled rxjs
I re-installed rxjs
I deleted my node_modules folder
I deleted my package-lock.json
I ran npm clean cache --force
I ran npm install
Then everything started working again :)

I'm using Angular 8.1, and the same issues cropped up.

Use of the exact following declaration solved the issue:

import {Subscription} from 'rxjs';

This imports the type from Angular declarations, so somehow the conflict isn't there anymore.

Was this page helpful?
0 / 5 - 0 ratings