Panda
Panda

Reputation: 415

How to fix "Type 'Promise<{}>' is missing the following properties from type 'Observable<any>'" in angular

Here's the code:

 const reportModules = [
      { url: '', params: { to: format(TODAY, DATE_FORMAT).toString(), from: format(TODAY, DATE_FORMAT).toString() } },
      {
        url: 'application1',
        params: { to: format(TODAY, DATE_FORMAT).toString(), from: format(TODAY, DATE_FORMAT).toString() }
      },
      {
        url: 'application2',
        params: {
          to: format(endOfWeek(TODAY), DATE_FORMAT).toString(),
          from: format(startOfWeek(TODAY), DATE_FORMAT).toString()
        }
      },
      {
        url: 'application3',
        params: {
          to: format(endOfWeek(TODAY), DATE_FORMAT).toString(),
          from: format(startOfWeek(TODAY), DATE_FORMAT).toString()
        }
      }
    ];

    const promises = reportModules.map(
  target =>
    new Promise(resolve => {
      this.notificationService
        .getSummary(target.url, target.params)
        .pipe(take(1))
        .subscribe(
          (result: Response) => {
            resolve({ target, result });
          },
          (err: Error) => {
            // return reject(err);
          }
        );
    })
);
        const observables: Observable<any>[] = promises;

        merge(...observables).subscribe((results) => { ... }

how to fix the error let observables: Observable<any>[] 'observables' is declared but its value is never read.ts(6133) Type 'Promise<{}>[]' is not assignable to type 'Observable<any>[]'. Type 'Promise<{}>' is missing the following properties from type 'Observable<any>': _isScalar, source, operator, lift, and 6 more.ts(2322).

What I'm trying to do here to load the first call then second until the end of the promise.

for example it will call the first which is the application1 after that the application2, it should call it one by one.

Upvotes: 0

Views: 4527

Answers (1)

Michael
Michael

Reputation: 135

The error is in the last two lines of your code. You're assigning a list of promises to a list of observables. They're not the same type of object.

The simplest fix would be to just stick to Promises and use Promise.all() instead of merge().

Upvotes: 1

Related Questions