Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase : firebase.Promise<any> compatibility with Rxjs Promise<any>

I'm trying to convert a firebase.Promise into an Observable using a project generated by angular-cli.

Here it's said that firebase.Promise are compatible with Native Promise and Promise/A+ implementation.

However I get an error when I try to use the Observable.fromPromise() method of rxjs.

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>'.

It actually work but having error is annoying, any idea about how to avoid this error in a clean way ?

Thanks.

like image 940
Thib Avatar asked Sep 29 '16 11:09

Thib


1 Answers

In TypeScript you can use type casting:

let promise = firebase.whatever();
Observable.fromPromise(<Promise<any>>promise);
like image 130
martin Avatar answered Oct 16 '22 21:10

martin