I'd like a type to express the following transformation:
// any key in this union that maps to a string value
// in the original type should become a date in the transformed // type
type DateFields = "createdAt" | "startDate"
type originalType = {
createdAt: string
foo: string
bar: {createdAt: string,
startDate: string,
foo: number,
baz: string[]
}
}
type newType = {
createdAt: Date
foo: string
bar: {createdAt: Date
startDate: Date
foo: number
baz: string[]}
}
Basically I want a type to express the effect of the (recursive) function that traverses an object, checks if it has certain keys, and changes the value associated with that key from a string to a Date instance.
I'm having trouble expressing a conditional mapped type where there's a conditional branching off the type of the keys. Any help would be appreciated!