How can I import the Typescript Subscription type from the Aurelia Store Subscribe method?

2k Views Asked by At

I am following the documentation for Aurelia Store on how to subscribe to the stream of store changes. When I import the typescript Subscription type from rxjs I get a typescript compilation error: TS2322: Type 'import("project\node_modules\aurelia-store\node_modules\rxjs\internal\Subscription") is not assignable to type import("project\node_modules\rxjs\internal\Subscription")

Code example:

// app.ts
import { autoinject } from "aurelia-dependency-injection";
import { Store } from "aurelia-store";
import { Subscription } from 'rxjs';
import { State } from "./state";

@autoinject()
export class App {

  public state: State;
  private subscription: Subscription;

  constructor(private store: Store<State>) {}

  bind() {
    this.subscription = this.store.state.subscribe(
      (state) => this.state = state
    );
  }

  unbind() {
    this.subscription.unsubscribe();
  }
}

I've tried doing import { Store, Subscription } from 'aurelia-store' but that doesn't work either.

EDIT:

In response to Pierre-Luc Champigny's question:

Are both your rxjs version (from Aurelia and your installed rxjs) the same?

So, aurelia-store/package.json has rxjs version "^6.2.2" and my projects package.json is "6.3.2". So, I uninstalled my rxjs version and installed the 6.2.2 version. Now typescript is giving this error message:

TS2322: Type 'import("project/node_modules/aurelia-store/node_modules/rxjs/internal/Subscription").Subscription' is not assignable to type 'import("project/node_modules/rxjs/internal/Subscription").Subscription'. Property '_parent' is protected but type 'Subscription' is not a class derived from 'Subscription'.

1

There are 1 best solutions below

3
Evan Larsen On BEST ANSWER

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

  1. I uninstalled rxjs
  2. I re-installed rxjs
  3. I deleted my node_modules folder
  4. I deleted my package-lock.json
  5. I ran npm clean cache --force
  6. I ran npm install

Then everything started working again :)