Open euberdeveloper opened 2 years ago
I worked on such problem and my idea is:
type _Update<T, U, S> = {
0: Exclude<U, T> extends T ? (Exclude<T, U> | S) : T,
1: S
}[[T] extends [U] ? [U] extends [T] ? 1 : 0 : 0]
type Update<T extends object, U, S> = {
[K in keyof T]: T[K] extends object ? Update<T[K], U, S> : _Update<T[K], U, S>
}
type a1 = {
b1: symbol | string | number
b2: symbol | string
b3: symbol
b4: string
b5: {
c1: 'c1'
c2: number
c3: number | symbol
}
}
type test = Update<a1,symbol, boolean>
Is your feature request related to a real problem or use-case?
If an API returns an object with some dates, such as
The date will become a string due to json conversion:
I want a type such that:
Describe a solution including usage in code example
A solution could be
But note that it does not support deep, so it should be perfectionated.
Who does this impact? Who is this for?
Everyone that has my problem
Describe alternatives you've considered (optional)
Additional context (optional)