Skip to content

Instantly share code, notes, and snippets.

@Yimiprod
Last active September 21, 2023 15:07
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 Yimiprod/60bfc8f0e01cf7c9b96ffea9d695a092 to your computer and use it in GitHub Desktop.
Save Yimiprod/60bfc8f0e01cf7c9b96ffea9d695a092 to your computer and use it in GitHub Desktop.
type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = Omit<T, Keys> &
{ [K in Keys]-?: Required<Pick<T, K>> & Partial<Omit<T, K>> }[Keys];
type RequireOnlyOne<T, Keys extends keyof T = keyof T> = Omit<T, Keys> &
{ [K in Keys]: Required<Pick<T, K>> & Partial<Record<Exclude<Keys, K>, undefined>> }[Keys]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment