MutuallyExclusive<T>: T extends [infer Head, ...(infer Tail)]
    ? Head extends string
        ? Tail extends string[]
            ? AllDisjoint<Head, Tail> extends true
                ? MutuallyExclusive<Tail>
                : AllDisjoint<Head, Tail>
            : true
        : true
    : true

Returns true if there is no intersection between the elements of T.

Type Parameters

  • T extends string[]

    The tuple of string types to check for mutual exclusivity.

true if there is no intersection between the elements of T, otherwise a custom error type.

type ReturnsTrue = MutuallyExclusive<['a', 'b' | 'c', 'd']>;
// true

type ReturnsError = MutuallyExclusive<['a', 'b' | 'c', 'c']>;
// { __error__: 'overlaps on c' }