-
-
Notifications
You must be signed in to change notification settings - Fork 227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a type "Swap<T, Replaced, Replacing> #176
Comments
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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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)
The text was updated successfully, but these errors were encountered: