QuickSnip LogoA light blue logo with a thunderbolt in bracketsQuickSnip

At Least One Key

Ensures that at least one property of an object is required.

  • helper-types
  • typedefinition

Install

npx shadcn@latest add https://quicksnip.dev/r/at-least-one-key.json

This snippet is not verified yet. Review it before use, or help verify it.

Code

type AtLeastOne<T> = {
    [K in keyof T]: Pick<T, K> & Partial<Omit<T, K>>;
}[keyof T];

Usage

type A = {
    id?: string;
    name?: string;
    isActive?: boolean;
};

type AtLeastOneA = AtLeastOne<A>;
// Requires at least one of 'id', 'name', or 'isActive' to be defined