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?