Skip to content

Instantly share code, notes, and snippets.

@clo4
Created April 14, 2022 02:30
Show Gist options
  • Select an option

  • Save clo4/59288283b97626b0c996e92938b915fb to your computer and use it in GitHub Desktop.

Select an option

Save clo4/59288283b97626b0c996e92938b915fb to your computer and use it in GitHub Desktop.
Create groups of properties that must be provided together
type OptionalGroup<T> = T | { [K in keyof T]?: undefined };
// deno-fmt-ignore
type OptionalGroups<Sets extends unknown[]> = Sets extends [infer Head, ...infer Rest]
? Rest extends []
? OptionalGroup<Head>
: OptionalGroup<Head> & OptionalGroups<Rest>
: Sets;
export type PropertySets<Base, Sets extends unknown[]> =
& Base
& OptionalGroups<Sets>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment