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

119
Vistas
How to solve multi type object data in single parameter

I declare this to receive options params value where value can be a single string or another object like options?: string[] | IServiceDetail[] | IServiceAccordion[];

But when I am trying to map the above objects getting an error:

Property 'title' does not exist on type 'string | IServiceAccordion | IServiceDetail'.
  Property 'title' does not exist on type 'string'.

Screenshot

return options?.map(
                  (category: string | IServiceDetail | IServiceAccordion) => {
                    return (
                      <Text
                        key={category.title}
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

you can check if the type is not a string before accessing the title, because a string is a primitive and does not have any property:

   options?.map((category: string | IServiceDetail | IServiceAccordion) => { 
     if(typeof category !== "string") return <Text key={category.title} />
     else return return <Text key={category} />
   }
about 4 years ago · Juan Pablo Isaza Denunciar

0

because string is a premitive type. so doesn't have "title" attribute. if you are sure that category is not string and is object and also has "title" attribute, you can use type casting

<Text
  key={(category as IServerDetail).title}
/>
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