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

163
Views
Error de tipo de reacción "no asignable al parámetro de tipo 'nunca'"

Lo que quiero hacer es recorrer el posttipo actual y los 'productos', pero estoy luchando con los tipos. Entonces obtuve el siguiente error:

El argumento de tipo 'Record<string, any>[]' no se puede asignar al parámetro de tipo 'nunca'.

En esta parte:

 ...pages.map((page) => ({

de mi código:

 const pages = useSelect((select) => { const editor = select("core/editor"); const currentPostType: string = editor.getCurrentPostType(); const selectablePostTypes = [currentPostType, "products"]; const postList = []; selectablePostTypes.forEach((singlePostType) => { const records: Record<string, any>[] = select("core").getEntityRecords( "postType", singlePostType ); postList.push(records); }); }); // Make dropdown of pagesOptions const pagesOptions = [ ...[ { value: "0", label: __("No page selected", "demosite"), }, ], ...pages.map((page) => ({ value: page.id, label: page.title, })), ];

Agregue el código que funciona:

 const pages = useSelect((select) => { const editor = select("core/editor"); const postType: string = editor.getCurrentPostType(); const records: Record<string, any>[] = select("core").getEntityRecords( "postType", postType ); return records ? records.map((record) => ({ description: record.description, id: record.id, featuredMedia: record.featuredMedia, link: record.link, subtitle: record.subtitle, title: record.title.rendered, })) : []; });

Aquí está dirigido a un tipo de publicación, el tipo de publicación que está editando actualmente, pero quiero repetir esto en algunos tipos de publicación.

Ejemplos:

 const selectablePostTypes = ['page', 'post', 'product'];
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Es su inicialización de postList

 const postList = [];

Debido a que no le ha proporcionado ningún valor para que TypeScript "descubra" la firma de tipo del contenido que debería pertenecer a esa matriz, lo establece como

 never[]

Esto significa que le prohíbe agregar cualquier valor a esa matriz vacía. Añadir un tipo aquí

 const postList: Record<string, any>[][] = [];
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!