UnionToIntersection<T>Transforms a union type into an intersection type.
When to use
Use to combine all members of a union into a single type with all their properties. This is useful in advanced generic code where you need to merge union variants.
Details
- Uses distributive conditional types and contra-variant inference.
- If the union members are incompatible (e.g.
string | number), the result isnever.
Example (Converting a union to an intersection)
import type { Types } from "effect"
type Union = { a: string } | { b: number }
type Result = Types.UnionToIntersection<Union>
// { a: string } & { b: number }typesIsUnion
Source effect/Types.ts:2192 lines
export type type UnionToIntersection<T> = (
T extends any ? (x: T) => any : never
) extends (x: infer R) => any
? R
: never
Transforms a union type into an intersection type.
When to use
Use to combine all members of a union into a single type with all their
properties. This is useful in advanced generic code where you need to merge
union variants.
Details
- Uses distributive conditional types and contra-variant inference.
- If the union members are incompatible (e.g.
string | number), the
result is never.
Example (Converting a union to an intersection)
import type { Types } from "effect"
type Union = { a: string } | { b: number }
type Result = Types.UnionToIntersection<Union>
// { a: string } & { b: number }
UnionToIntersection<function (type parameter) T in type UnionToIntersection<T>T> = (function (type parameter) T in type UnionToIntersection<T>T extends any ? (x: Tx: function (type parameter) T in type UnionToIntersection<T>T) => any : never) extends (x: Rx: infer function (type parameter) RR) => any ? function (type parameter) RR
: neverReferenced by 7 symbols