RxJs operators causing typescript errors

63 Views Asked by At

Working version:

   const observable = Observable
      .from([Promise.resolve('1'), Promise.resolve('2')])
      .subscribe((results) => {})

Broken version (added mergeAll operator):

const observable = Observable
  .from([Promise.resolve('1'), Promise.resolve('2')])
  .mergeAll()
  .subscribe((results) => {})

Propery 'subscribe' doesn't exist on type 'Promise<{string}>'

I'm using the basic Angular CLI setup.

What might be the reason?

1

There are 1 best solutions below

0
On

Whenever you are returning the resolving the promise. You should be using fromPromise operator as below

const observable = Observable
  .fromPromise([Promise.resolve('1'), Promise.resolve('2')])
  .mergeAll()
  .subscribe(results => console.log(results));

Also try logging the results as in the code.