Hyperlinkv0.8.0-beta.28

Types

Types.UnionToIntersectiontypeeffect/Types.ts:219
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 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 }
typesIsUnion
Source effect/Types.ts:2192 lines
export type UnionToIntersection<T> = (T extends any ? (x: T) => any : never) extends (x: infer R) => any ? R
  : never
Referenced by 7 symbols