Skip to content

Instantly share code, notes, and snippets.

@gustavohenke
Created July 13, 2022 06:20
Show Gist options
  • Save gustavohenke/826359a784235c17bb3643d841dbec40 to your computer and use it in GitHub Desktop.
Save gustavohenke/826359a784235c17bb3643d841dbec40 to your computer and use it in GitHub Desktop.
/**
* Recursively unions the types of the properties of T.
* TODO: Deal with arrays
*
* @example
* type SomeObject = { a: { b: { c: boolean } }, d: string };
* const x: DeepUnion<SomeObject>; // boolean | string
*/
type DeepUnion<T extends object> = {
[K in keyof T]: T[K] extends object ? DeepValues<T[K]> : T[K];
}[keyof T];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment