如何从 Aurelia Store Subscribe 方法导入 Typescript Subscription 类型?

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

我正在关注 Aurelia Store 关于如何订阅商店变更流的文档。当我从 rxjs 导入打字稿 Subscription 类型时,出现打字稿编译错误: 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")

代码示例:

// 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();
  }
}

我试过import { Store, Subscription } from 'aurelia-store',但也没用。

编辑:

回复 Pierre-Luc Champigny 的问题:

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

因此,aurelia-store/package.json 的 rxjs 版本为“^6.2.2”,而我的项目 package.json 为“6.3.2”。所以,我卸载了我的 rxjs 版本并安装了 6.2.2 版本。现在打字稿给出了这个错误信息:

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. 我卸载了 rxjs
  2. 我重新安装了 rxjs
  3. 我删除了我的 node_modules 文件夹
  4. 我删除了我的包裹-lock.json
  5. 我运行npm clean cache --force
  6. 我运行npm install

然后一切又开始工作了:)