platform-bible-utils
    Preparing search index...

    Type Alias UnionToIntersection<U>

    UnionToIntersection: (U extends any ? (x: U) => void : never) extends (
        x: infer I,
    ) => void
        ? I
        : never

    Converts a union type to an intersection type (| to &).

    Note: this utility type is for use on object types. It may fail on other types.

    Type Parameters

    • U
    type TypeOne = { one: string };
    type TypeTwo = { two: number };
    type TypeThree = { three: string };

    type TypeNums = { one: TypeOne; two: TypeTwo; three: TypeThree };
    const numNames = ['one', 'two'] as const;
    type TypeNumNames = typeof numNames;

    // Same as `TypeOne | TypeTwo`
    // `{ one: string } | { two: number }`
    type TypeOneTwoUnion = TypeNums[TypeNumNames[number]];

    // Same as `TypeOne & TypeTwo`
    // `{ one: string; two: number }`
    type TypeOneTwoIntersection = UnionToIntersection<TypeOneTwoUnion>;