When defining my initial type First
:
type First = {
a: string,
b: number
}
I am open to different approaches in implementing the Dictionary
type. An alternative dictionary structure could be:
type Dictionary = {
string: { "stringValue": string },
number: { "numberValue": number }
}
My main query is how can I create a generic transformation function Transform<T>
that will transform the First
type into:
type Second = {
a: { "stringValue"": string },
b: { "numberValue": number }
}
Unfortunately, I am unable to determine the typeof T
, which has made it difficult to perform an indexed access on the Dictionary
. While I have considered using a chain of conditional types manually, it seems like a less elegant solution.
type Dictionary<T> = T extends string ? { "stringValue": string } : { "numberValue": number }
type Second = {[Property in keyof First]: FieldValueOf<First[Property]>}