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

169
Vistas
Map a union to a string literal union of the type names

I have a type like this (in this case, the user would be a custom interface):

export type ArgumentTypes = string | number | boolean | user;

now, I would like to have a type of

export type ArgumentTypeNames = "string" | "number" | "boolean" | "user";

I've tried to search around myself for a while, but I have not been able to find a way to get the name. I tried to do ${ArgumentTypes} but that didn't work.

I'm pretty new to advanced types ( Mapped, conditional, and so on ) so I would love an explanation of the answer, or of potential solutions.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

AFAIK, as of today's version of TypeScript, you can't do that without an explicit mapping of string to "string", number to "number" etc. existing somewhere in your program. The mapping might look like this:

interface TypeMapping {
  string: string;
  number: number;
  boolean: boolean;
  user: user;
}

However, not all is lost. You could make this mapping the source of truth, and derive other types from it:

type ArgumentTypeNames = keyof TypeMapping;
type ArgumentTypes = TypeMapping[ArgumentTypeNames];

Try it.

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