Angular 2 - Typescript:TS2322:类型'Subscription'不能分配给'Observable <MouseEvent>'类型

Shi*_*ara 3 mouseevent observable rxjs typescript angular

我正在使用此插件中的click-outside指令 - > http://embed.plnkr.co/v7BMUv/

我的TS编译器抛出以下错误:

TS2322:类型'订阅'不能分配给'Observable'类型."订阅"类型中缺少"_isScalar"属性.

TS2339属性'unsubscribe'在'Observable'类型中不存在.

我的tsconfig.json:

{
  "compileOnSave": false,
  "compilerOptions": {
    "target": "es6",
    "module": "system",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "suppressImplicitAnyIndexErrors": true,
    "noImplicitAny": false,
    "noEmitOnError": false
  },
  "exclude": [
    "node_modules",
    "wwwroot"
  ]
}
Run Code Online (Sandbox Code Playgroud)

代码导致错误:

  ngOnInit() {
    this.globalClick = Observable
      .fromEvent(document, 'click')
      .delay(1)
      .do(() => {
        this.listening = true;
      }).subscribe((event:MouseEvent) => {
        this.onGlobalClick(event);
      });
  }
  
Run Code Online (Sandbox Code Playgroud)

我该如何克服这个错误?

Ion*_*ica 9

错误在于click-outside.directive.ts.Observable.subscribe返回Subscription(in ngOnInit),而不是另一个Observable.因此,private globalClick应该是这种类型Subscription.

它在删除类型时起作用,并且当plunker没有显示它工作的类型错误时,但是当tsc它用它编译时,当你试图将一个Subscription对象分配给它时会出错Observable.