Package: effect
Module: Unify
Unifies types that implement the unification protocol.
When to use
Use to normalize unions of types that expose Effect’s unification protocol.
Details
This type performs automatic type unification for types that contain
the unification symbols (unifySymbol, typeSymbol, ignoreSymbol).
It’s primarily used internally by the Effect type system to handle
complex type unions and provide better type inference.
Example (Unifying protocol types)
import type { Unify } from "effect"
// Example of types that can be unified
type UnifiableA = {
value: string
[Unify.typeSymbol]?: string
[Unify.unifySymbol]?: { String: () => string }
}
type UnifiableB = {
value: number
[Unify.typeSymbol]?: number
[Unify.unifySymbol]?: { Number: () => number }
}
// Unify automatically handles the union
type Unified = Unify.Unify<UnifiableA | UnifiableB>
// Results in a properly unified type
See
unify for applying this normalization to a value or functionSignature
type Unify<A> = Values<
ExtractTypes<
(
& FilterIn<A>
& { [typeSymbol]: A }
)
>
> extends infer Z ?
| Z
| FilterInUnmatched<
A,
Keys<
ExtractTypes<
(
& FilterIn<A>
& { [typeSymbol]: A }
)
>
>
>
| FilterOut<A>
: never
Since v2.0.0