Search code examples
typescriptrxjsngrxrxjs-pipeable-operators

Are there any way to filter of{} not put aditional map?


I have pipe and It will return of{} when some error occured. So I need to filter it , to other code flows. Currently I used following senario. I need to know , are there any way to remove map and filter it in the exiting filter ?

 readonly k$ = combineLatest(
    [this.x$.pipe(filter(isNotNullOrUndefined), //this filter not filtering  of{} type.
      map((res: A) => {  //need to remove this map
        return res;
      })
    ), this.y$]).pipe(shareReplayUntil(this.destroySub));

Solution

  • You can return of(null) instead of of({}) so that your filter function isNotNullOrUndefined filters the null value properly.