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

205
Vistas
Generating TypeScript types from a Map

Is it possible to generate typescript type from a JS Map or equivalent objects? eg.

type SampleType<T> = {
    name: string;
    handle: (value: string) => T;
 };

I have a list of objects like this

[{name: "update", handle: (value: string) => new Date(value)} as SampleType<Date>, {name: "orig", handle: (value: string) => value} as SampleType<string>, {name: "age", handle: parseFloat} as SampleType<number>]

(I mentioned JS Map cause as I can easily convert this into a map where the name is the key, and rest of the object is the value)

Now, I want to generate a type dynamically such that the value of the "name" is the key, and the type is derived from the handle function (or from type of SampleType<>) i.e.

type Result = {
    update: Date;
    orig: string;
    age: number;
};

Is it possible to generate such a type dynamically in typescript?

about 4 years ago · Juan Pablo Isaza
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