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

102
Vistas
typescript limit type to enum only

I have the following code:

enum MY_ENUM {
    A,
    B,
    C
}

type MY_TYPE = {
    field: MY_ENUM
}

// Error: Type '{ field: string; }[]' is not assignable to type 'MY_TYPE[]'.
const myArray: MY_TYPE[] = Object.keys(MY_ENUM).map(key => {
    return {
        field: key,  // key is a string, but I want it to be MY_ENUM
    }
})

It gives an error on myArray, saying string is not assignable to type 'MY_TYPE'.`, so how do I get the enum typed key instead of string? Or in another word, how can I iterate enum, gets the actual enum typed key but not its string representation?

example

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