Skip to content

Instantly share code, notes, and snippets.

@gustavohenke
Created July 13, 2022 06:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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