Type alias UnionToIntersection<U>

UnionToIntersection<U>: (U extends unknown
        ? ((arg) => unknown)
        : never) extends ((arg) => void)
    ? I
    : never

As the name implies, it turns a union into an intersection

Type Parameters

  • U

Example

type ExpectedToBe = (() => 'foo') & ((baz: 88) => Optional<T>);

type T = NewType<'T', string>;
type Result = UnionToIntersection<
(() => 'foo') | ((baz: 88) => Optional<NewType<'T', string>>)
>
// Result: ExpectedToBe

type Result2 = UnionToIntersection<
IsFalsy<0> | IsDeepImmutable<{ a: string; readonly b: string }>
>
// Result 2: IsFalsy<0> & IsDeepImmutable<{ a: string; readonly b: string }> => true & true => evaluates to true