i saw that rxjs will deprecate toPromise(). We should use lastValueFrom instead. I want to ask what the Reason behind this is?
The Syntax .toPromise() was much more clean.
i saw that rxjs will deprecate toPromise(). We should use lastValueFrom instead. I want to ask what the Reason behind this is?
The Syntax .toPromise() was much more clean.
This topic has been covered by several public talks from Ben Lesh about rxjs7. To summarize, .toPromise() never really functioned correctly. This is because the response will either be the resolved value, or undefined <T | undefined>, which is not how promises work. However, .lastValueFrom() will return a promise of type <T> or it will throw an empty error if no value is emitted. The added benefit is that .lastValueFrom() is configurable and that you can assign the default value should the observable not emit anything.