RecipesChapter 8: Helper Types

Allowing Exactly One and All or None

Recipe 8.8 from The TypeScript Cookbook

type AllOrNone<T, Keys extends keyof T> = (
  | Required<Pick<T, Keys>>
  | Partial<Record<Keys, never>>
) &
  Split<T>;
Open in TypeScript Playground →