Imagine I have the following specified object:
type Test = {
date: Date
num: number
str: string
}
In this object, there is a Date type that needs to be converted into a string ("serialized"). To achieve this, I came up with the concept of a Generic Type as shown below:
type Serializer<T extends {[key: string]: unknown}> = {
[key in keyof T]: T[key] extends Date ? string : T[key]
}
This Generic Type performs the task effectively. You can experiment with it on this playground link.
https://i.sstatic.net/X6rrv.png
Now, if I have a type of Test[]
, what kind of generic type could help me "serialize" this particular data structure?