Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

159
Vistas
React type error "not assignable to parameter of type 'never'"

What I want to do is loop over current posttype and 'products' but I'm struggling with the types. So I got the following error:

Argument of type 'Record<string, any>[]' is not assignable to parameter of type 'never'.

On this part:

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

of my code:

  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,
    })),
  ];

Add the code which works:

  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,
        }))
      : [];
  });

Here it is targeted on one post type, the post-type you're currently editing, but I want to loop this over some posttypes.

Examples:

const selectablePostTypes = ['page', 'post', 'product'];
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It is your initialization of postList

const postList = [];

Because you haven't provided it any values for typescript to "figure out" the type signature of the content that should belong in that array, it sets it as

never[]

This means it bans you from adding any values to that empty array. Add a type here

const postList: Record<string, any>[][] = [];
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda