Angular/rxjs: Why don't I have to import toPromise anymore? [closed]

纵饮孤独 提交于 2019-12-18 06:49:15

问题


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



来源:https://stackoverflow.com/questions/46838807/angular-rxjs-why-dont-i-have-to-import-topromise-anymore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!