Search code examples
rxjsrxjs5rxjs-lettable-operators

mergeAll not working the same as a lettable operator (rxjs 5.5+)?


Before lettable operators, the code looked like this:

get someData$(): Observable<Data> {
  return this.dataService.higherOrderDataStream
    .mergeAll()
    .map(...);
}

Refactoring to use pipe, I get a type error essentially saying Observable<Observable<Data>> is not assignable to type Observable<Data>:

get someData$(): Observable<Data> {
  return this.dataService.higherOrderDataStream
    .pipe(
      mergeAll(),
      map(...)
    );
}

But the following works just fine (I assume one shouldn't mix lettable and chained operators):

get someData$(): Observable<Data> {
  return this.dataService.higherOrderDataStream
    .mergeAll()
    .pipe(
      map(...)
    );
}

Is there a different mergeAll I should be using? I'm using the one from rxjs/operators where I was using rxjs/add/operator/mergeAll previously. I thought these two implementations would be equivalent.

Is this a bug or am I using the new mergeAll incorrectly?


Solution

  • This is a known bug in RxJS 5.5 with mergeAll and concatAll. It'll be fixed in RxJS 6.

    For more details see: https://github.com/ReactiveX/rxjs/issues/2759

    Fix was merged few days ago: https://github.com/ReactiveX/rxjs/pull/3321

    For now it's better to use mergeMap(o => o) or concatMap(o => o) instead.