I have a unique object structure where each property holds a different type of function, all taking the same parameter and returning distinct objects.
const initialObj = {
a: (c: number) => ({ c }),
b: (c: number) => ({ d: c }),
}
Now, I aim to generate another object based on this structure. The new object should mirror the keys of the original, with values as the objects returned by the functions:
{
a: { c: 4 };
b: { d: 4 };
}
I attempted to define the typing like so:
{ [Key in typeof keyof initialObj]: ReturnType<typeof initialObj[Key]> }
However, this produced a union type output:
{
a: { c: number } | { d: number };
b: { c: number } | { d: number };
}
The desired final result is as follows:
{
a: { c: number };
b: { d: number };
}
Would it be feasible to achieve this, and if so, how can I correctly define the typings?