Rxjs:[ts] 属性 'pipe' 在类型 'UnaryFunction<Observable<{}>, Observable<string | {}>>' 上不存在。任何

Rxjs : [ts] Property 'pipe' does not exist on type 'UnaryFunction<Observable<{}>, Observable<string | {}>>'. any

我正在尝试实现 ngbTypeAhead ,但使用 5.5.5 版本的 RxJS 有问题。我从 rxjs 6 版本中获取了这个例子。

"rxjs": "^5.5.2" and
 angular "^5.0.1",
"typescript": "~2.6.1",

当我尝试在焦点上实现提前输入时,出现类似 ,

的错误
 *[ts] Property 'pipe' does not exist on type 'UnaryFunction<Observable<{}>, Observable<string | {}>>'.
any*


search2 = (text$: Observable<string>) => {
    const debouncedText$ = text$.pipe(debounceTime(200), distinctUntilChanged());
    const clicksWithClosedPopup$ = this.click$.pipe(filter(() => !this.instance.isPopupOpen()));
    const inputFocus$ = this.focus$;

    let mer = merge(debouncedText$, inputFocus$, clicksWithClosedPopup$);
    debugger;
    return mer.pipe(
      map(term => (term === '' ? this.roadList
        : this.roadList.filter(v => v.toLowerCase().indexOf(term.toString().toLowerCase()) > -1)).slice(0, 10))
    );
  }

谁能帮我解决如何重写上面的 search2 方法的问题?

您很可能将 merge 作为运算符导入,而您想要 merge 它所谓的 "Observable creation method" 并直接来自'rxjs'.

所以检查一下你是否真的在 RxJS 6 中使用这个导入:

import { merge } from 'rxjs';

...而不是导入您不想要的 merge 运算符的导入:

import { merge } from 'rxjs/operators'; // This imports just the operator

对于 RxJS 5,使用以下内容:

import { merge } from 'rxjs/observable/merge';