Search code examples
angulartypescriptrxjsangular5rxjs5

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


I'm trying to implement ngbTypeAhead , but having an issue with RxJS , using 5.5.5 version . I've took this example from rxjs 6 version .

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

when I tried to implement typeahead on focus , getting an error like ,

 *[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))
    );
  }

could anyone please help me figure it the issue how to rewrite the above search2 method?


Solution

  • You're most likely importing merge as an operator while you want merge that it so called "Observable creation method" and comes directly form 'rxjs'.

    So check if you're really using this import in RxJS 6:

    import { merge } from 'rxjs';
    

    ...instead of this import that imports merge operator that you don't want:

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

    For RxJS 5 use the following:

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