Home > Back-end >  How to solve the TS type error when trying to get firebase data by using orderByChild?
How to solve the TS type error when trying to get firebase data by using orderByChild?

Time:06-29

I need to get all the players ordered by their points from Firebase(V9) Realtime Database. I tried to fetch them as it is instructed in the docs.

But ref(db, 'usersPoints') throws this TypeScript error:

Argument of type 'DatabaseReference' is not assignable to parameter of type 'Query<unknown>'. Type 'DatabaseReference' is missing the following properties from type 'Query<unknown>': converter, type, firestore, withConverter

Here is the code:

const db = getDatabase();
const playersByPoints = query(ref(db, "usersPoints"), orderByChild("points"));

CodePudding user response:

It looks like you're importing query from firebase/firestore, instead of firebase/database.

  • Related