I am in need of a TypeScript type that can duplicate another object type while adjusting the types of properties based on their original conditions. This adjustment should apply to all nested and deeply nested properties as well.
For instance, consider a type called DateToStrings<T>
that converts all properties of type Date
into properties of type string
. Here is an example:
If we have a class:
class Milk {
brandName: string,
price: number,
dealExpiredAt: Date,
properties: {
expirationDetails: {
expiredAt: Date
}
}
}
The resulting type DateToStrings<Milk>
would be:
{
brandName: string,
price: number,
dealExpiredAt: string,
properties: {
expirationDetails: {
expiredAt: string
}
}
}
I could really use some guidance on how to tackle this problem. Any tips or suggestions for existing types/packages that might accomplish something similar?