Reputation: 10949
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.
Upvotes: 3
Views: 989
Reputation: 96969
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)
);
Upvotes: 4