I want to get all users from a Firebase realtime database and sort them by a score property. I've got this to work using the variable
Type 'Observable<any>' is not assignable to type 'FirebaseListObservable<any>'.
Property '_ref' is missing in type 'Observable<any>'.
this.users = this.af.database.list('/users')
.map(items => items.sort((a, b) => b.score - a.score));
lift, so RxJS operators - like
map - will return a
It's just that - when using TypeScript - the RxJS operators are statically typed to return
Observable, so you have to cast to
FirebaseListObservable. (Using RxJS does not have to involve TypeScript and if you look at the guidance for adding operators you will see that types are not mentioned.)
You can verify that a
FirebaseListObservable instance is returned by looking for the
update functions you mentioned in your question:
this.users = this.af.database .list('/users') .map(items => items.sort((a, b) => b.score - a.score)) as FirebaseListObservable<any>; console.log(this.users.push.toString()); console.log(this.users.update.toString());
Note, however, that this will not work for
FirebaseListObservable instances that are created as queries. There is an as-yet-unanswered question regarding such instances.