devtypes - v1.1.0
    Preparing search index...

    Type Alias RequireExactlyOne<T, K>

    RequireExactlyOne: {
        [P in K]: Required<Pick<T, P>> & Partial<Record<Exclude<K, P>, never>> & Omit<
            T,
            K,
        >
    }[K]

    Require exactly one property from a set.

    Type Parameters

    • T

      Source object type

    • K extends keyof T = keyof T

      Keys where exactly one must be present (defaults to all keys)

    Produces a union of object variants where exactly one of the specified properties is present and all others are explicitly disallowed.

    type Test = { a?: string; b?: number; c: boolean };
    type Result = RequireExactlyOne< Test, 'a' | 'b' >;
    // { a: string; b?: never; c: boolean } | { a?: never; b: number; c: boolean }