I'm trying to build a firestore query conditionally but I'm getting a typescript error and I don't know what I'm missing. Below is my code.
const getInitialData = ({ collection, orderClause }: ICollection) => {
let query = app.collection(collection);
if (orderClause) {
query = query.orderBy(orderClause.value, orderClause.direction);
}
query.get().then((response) => {
const genericData: T[] = [];
response.forEach((doc) => {
genericData.push(dataResolver(doc));
});
setData(genericData);
});
};
I'm getting the error "Type 'Query' is missing the following properties from type 'CollectionReference': id, parent, path, doc, addts(2739)" when updating the query inside the if statement.
Thanks in advance!