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.
In TypeScript you can use type casting:
let promise = firebase.whatever();
Observable.fromPromise(<Promise<any>>promise);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With