Skip to content

Instantly share code, notes, and snippets.

@cmrigney
Created June 21, 2022 20:21
Show Gist options
  • Select an option

  • Save cmrigney/1fb83077a585303bc52c73e6831d5d29 to your computer and use it in GitHub Desktop.

Select an option

Save cmrigney/1fb83077a585303bc52c73e6831d5d29 to your computer and use it in GitHub Desktop.
Merge two object types recursively.
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