2016-09-29 38 views
6

我試圖使用由angular-cli生成的項目將firebase.Promise轉換爲ObservableFirebase:firebase.Promise <any>與Rxjs Promise的兼容性<any>

Here據說firebase.PromiseNative PromisePromise/A+兼容。

但是,當我嘗試使用rxjs的Observable.fromPromise()方法時出現錯誤。

Argument of type 'firebase.Promise<any>' is not assignable to parameter of type 'Promise<any>'.                
    Types of property 'then' are incompatible.                             
    Type '(onResolve?: (a: any) => any, onReject?: (a: Error) => any) => Promise<any>' is not assignable to type '{ <TResult1, TResult2>(onfulfilled: (value: 
any) => TResult1 | PromiseLike<TResult1>, onrejected:...'.                          
     Type 'firebase.Promise<any>' is not assignable to type 'Promise<any>'. 

它實際上是工作,但有錯誤是煩人,如何避免在一個乾淨的方式這個錯誤的任何想法?

謝謝。

+0

您使用的打字稿? – martin

+0

是的,我正在使用TS – Thib

回答

10

在打字稿你可以使用類型轉換:

let promise = firebase.whatever(); 
Observable.fromPromise(<Promise<any>>promise);