RxJS 5.5.6. I'm trying to convert an Observable<string[]> into Observable<string>
I'm not sure if mergeAll operator is what I'm looking for
const o1: Observable<string[]> = of(['a', 'b', 'c']);
const o2: Observable<string> = o1.pipe(
mergeAll()
);
Typescript will return this error:
Type 'Observable<string | string[]>' is not assignable to type 'Observable<string>'.
Type 'string | string[]' is not assignable to type 'string'.
Type 'string[]' is not assignable to type 'string'.
I receive Observable as parameter and I can change the way is constructed.
It looks like you've encountered an already reported RxJS issue, see https://github.com/ReactiveX/rxjs/issues/2759 and even more recent https://github.com/ReactiveX/rxjs/issues/3290.
From the comments it looks like it won't be fixed until RxJS 6.
However you can always use mergeMap(o => o)/concatMap(o => o) instead of mergeAll()/concatAll().
For example:
const o1: Observable<string[]> = of(['a', 'b', 'c']);
const o2: Observable<string> = o1.pipe(
mergeMap(o => o)
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With