Angular and Firebase Firestore throws TypeError: undefined is not an object (evaluating 'ref.onSnapshot')
this.fbstore
.collection(`claims`, ref => {
let query:
| firebase.default.firestore.CollectionReference
| firebase.default.firestore.Query = ref;
if(someValue === true) {
return query.where('field1', '==', 20);
}
}).valueChanges();
The problem is if someValue is false then query is not returned, adding else statement will solve the issue or add default return query. These types of errors are time consuming if you rely on IDE, Typescript to much, it's easy to see the problem on this sample code.
this.fbstore
.collection(`claims`, ref => {
let query:
| firebase.default.firestore.CollectionReference
| firebase.default.firestore.Query = ref;
if(someValue === true) {
return query.where('field1', '==', 20);
}
return query; // this will not run if someValue is true
}).valueChanges();