Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Angular 13 – How to resolve '(): Promise<Object | undefined>' is deprecated.ts(6385)

In my Angular-13 project, I am trying to get the data from API endpoint for chartjs. I have this in the service:

  getCurrentEmployeeChart() {
    return this.http.get(this.baseUrl + 'current-employee')
        .toPromise()
        .then((data) => {
          return data;
        });
  }

I got this error:

‘(): Promise<Object | undefined>’ is deprecated.ts(6385)
Observable.d.ts(125, 9): The declaration was marked as deprecated here.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Then:

toPromise()

is crossed.

How do I resolve this?

Thanks

>Solution :

See this:
https://rxjs.dev/deprecations/to-promise

Most likely you want to use lastValueFrom

import { interval, lastValueFrom } from 'rxjs';
import { take } from 'rxjs/operators';

async function execute() {
  const source$ = interval(2000).pipe(take(10));
  const finalNumber = await lastValueFrom(source$);
  console.log(`The final number is ${finalNumber}`);
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading