I encountered an error while running my Angular 8 app. It seems to be related to a potential bug in RxJS or maybe I am overlooking something.
import { of } from 'rxjs';
import { switchMap } from 'rxjs/operators';
of(1,2,3)
.pipe(
switchMap((x) => of(x + 1))
)
My expectation was for the subscriber to receive the output:
//2, 3, 4
However, what it is actually outputting is the observable returned within the switchMap operation:
//Observable<number>, Observable<number>, Observable<number>
SUMMARY
It appears that switchMap is returning a value of type
Observable<Observable<number>>
instead of just Observable<number>
.
I am unsure whether this issue is due to TypeScript or RxJS, but upon reverting back to version 6.0.0 of RxJS, the problem disappears.
Versions:
- Angular 8.0.0
- TypeScript 3.4.5
- RxJS 6.4.0
I have also tested and observed the same behavior with flatMap