Created
June 21, 2022 20:21
-
-
Save cmrigney/1fb83077a585303bc52c73e6831d5d29 to your computer and use it in GitHub Desktop.
Merge two object types recursively.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type Assign<T1, T2> = Omit<T1, keyof T2> & T2; | |
| type Merge<T1, T2> = T1 extends object | |
| ? T2 extends object | |
| ? Assign< | |
| T1, | |
| { | |
| [k in keyof T2]: Merge< | |
| k extends keyof T1 ? T1[k] : T2[k], | |
| T2[k] | |
| >; | |
| } | |
| > | |
| : T2 | |
| : T2; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment