Angular/rxjs: Why don't I have to import toPro

2019-01-26 20:18发布

问题:

A ton of SO answers say that to avoid problems like

Property 'toPromise' does not exist on type 'Observable'

in Angular, you have to import 'rxjs/add/operator/toPromise' which I've done until recently. In an Angular 4.2.4 project, I forgot the import and expected to see an error. It wasn't there! I did some debugging in Chrome's dev tools and saw "toPromise" on the Observable's prototype.

My question is ... how did that get there? Is this a new addition to TypeScript, Angular, or rxjs?

回答1:

As of rxjs 5.5.0-beta.5

toPromise: now exists as a permanent method on Observable (2e49a5c)

https://github.com/ReactiveX/rxjs/blob/master/CHANGELOG.md#550-beta5-2017-10-06