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

247
Vistas
Is it possible to get types from an unknown array?

I am getting Icon names from an imported library and mapping through them like this:

import * as Icons from "@icons";

// an array of icon names ["ArrowLeft", "ArrowRight" ect]
const IconNames = [...Object.keys(Icons).map((icon) => icon)] as const; 
// for sizes prop
const IconSizes = ["sm", "md", "lg"] as const; 

But when I try to get types from the array it just comes up as string:

icon: typeof IconNames[number]; //this is type string
size: typeof IconSizes[number]; //this is type "sm" | "md" | "lg"
};

Am I doing something wrong or is it not possible to get the type for icon from an unknown array "ArrowLeft" | "ArrowRight"?

Any help would be great.

Thanks

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

Yeh this is a gap in TypeScript: https://github.com/microsoft/TypeScript/pull/12253#issuecomment-263132208.

Your only choice is to cast it to keyof Icons.

about 4 years ago · Santiago Gelvez 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