Skip to content

Instantly share code, notes, and snippets.

@197291
Created June 7, 2019 14:19
Show Gist options
  • Save 197291/b7cf6f597e3e95927e2c51d3991c2922 to your computer and use it in GitHub Desktop.
Save 197291/b7cf6f597e3e95927e2c51d3991c2922 to your computer and use it in GitHub Desktop.
type RequireOnlyOne<T, Keys extends keyof T = keyof T> =
Pick<T, Exclude<keyof T, Keys>>
& { [K in Keys]-?:
Required<Pick<T, K>>
& Partial<Record<Exclude<Keys, K>, undefined>>
}[Keys]
type RequireAtLeastOne<T, Keys extends keyof T = keyof T> =
Pick<T, Exclude<keyof T, Keys>>
& {
[K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>>
}[Keys]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment