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

204
Visualizações
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 à 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