Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

246
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda