Difficulty with RxJS return values and documentation, converting between array and series of items

Joe Source

I'm a beginner working through basic examples with RxJS and Angular. I am using:

rxjs 5.5.6 angular 5.2.0

I'm getting the following error:

error TS2339: Property 'do' does not exist on type 'number[]'.

from the following code that converts back and forth between an array and a series of items. I am attempting to insert mergeAll in place of mergeMap, which compiles and works as expected in converting the array. I would expect an Observable returned from mergeAll according to the docs without having to cast, especially since mergeMap is based on mergeAll.


notWorking(): Observable<any> {
    return Observable.from([[1, 2, 3, 4]])
        .do(obj => console.log(obj))
        // .mergeMap(val => val)
        .do(obj => console.log(obj))
        .do(obj => console.log(obj))

In the documentation from ReactiveX RxJS, it shows only a return value of Observable for mergeAll. Am I looking at the right documentation? Am I not understanding something fundamental about RxJS?

public mergeAll(concurrent: number): Observable

Converts a higher-order Observable into a first-order Observable which concurrently delivers all values that are emitted on the inner Observables.

Reactive RxJS mergeAll documentation

If the case is that it is returning an iterable and this is intended, what is the best practice to chain observable operators? Do I have to cast between each chain or create an Observable? This doesn't make sense to me, I hope I'm just doing something wrong.



answered 8 months ago martin #1

This is a known issue in typings for mergeAll and concatAll in RxJS 5.5 that will be fixed in RxJS 6.

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

So the recommended way for now is really using what you did with .mergeMap(val => val).

comments powered by Disqus