Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

159
Views
Usar el operador de propagación en una matriz de filtros para crear una consulta de Firestore

Estoy trabajando en un componente de filtro para mi aplicación web React y quiero devolver (pasar a través de accesorios) una serie de condiciones para la consulta de Firestore.

Por ejemplo, si el usuario desea filtrar las publicaciones sin comentarios, marca una casilla de verificación y se agrega un where("commentsCount", ">", "0") a la matriz de filtros.

 const queryParams = [ collection(db, "posts"), orderBy(sortType, sortMethod), limit(POSTS_PER_PAGE), ]; const filters = [ where("commentsCount", ">", "0"), // And possibly more where's ]; queryParams.push(...filters); // Create a firestore query object using the parameters const _query = query(...queryParams);

Pero hacer esto me da un error de TypeScript: A spread argument must either have a tuple type or be passed to a rest parameter. TS2556 .

¿Qué estoy haciendo mal?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

No puede pasar un argumento de tipo (CollectionReference<DocumentData> | QueryConstraint)[] en query . Intente agregar collection() directamente en la query y elimínelo de queryParams para que sea una matriz de tipo QueryContraint[] :

 const queryParams = [ orderBy(sortType, sortMethod), limit(POSTS_PER_PAGE), ]; const filters = [ where("commentsCount", ">", "0"), // And possibly more where's ]; // Create a firestore query object using the parameters const _query = query(collection(db, "posts"), ...queryParams);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!