<
const I,
P extends {
readonly [Tag in Types.Tags<"_tag", I> & string]: (
_: Extract<I, { readonly _tag: Tag }>
) => any
} & { readonly [Tag in Exclude<keyof P, Types.Tags<"_tag", I>>]: never }
>(
fields: P
): (input: I) => Unify<ReturnType<P[keyof P]>>
<
const I,
P extends {
readonly [Tag in Types.Tags<"_tag", I> & string]: (
_: Extract<I, { readonly _tag: Tag }>
) => any
} & { readonly [Tag in Exclude<keyof P, Types.Tags<"_tag", I>>]: never }
>(
input: I,
fields: P
): Unify<ReturnType<P[keyof P]>>Creates a match function for a specific value with discriminated union handling.
Details
This function provides a convenient way to pattern match on discriminated unions
by providing an object that maps each _tag value to its corresponding handler.
It's similar to a switch statement but with better type safety and exhaustiveness checking.
Example (Matching value tags)
import { Match } from "effect"
type Status = { readonly _tag: "Success"; readonly data: string }
const success: Status = { _tag: "Success", data: "Hello" }
// Simple valueTags usage
const message = Match.valueTags(success, {
Success: (result) => `Success: ${result.data}`
})
console.log(message) // "Success: Hello"export const const valueTags: {
<
I,
P extends {
readonly [Tag in Types.Tags<"_tag", I> &
string]: (
_: Extract<
I,
{
readonly _tag: Tag
}
>
) => any
} & {
readonly [Tag in Exclude<
keyof P,
Types.Tags<"_tag", I>
>]: never
}
>(
fields: P
): (input: I) => Unify<ReturnType<P[keyof P]>>
<
I,
P extends {
readonly [Tag in Types.Tags<"_tag", I> &
string]: (
_: Extract<
I,
{
readonly _tag: Tag
}
>
) => any
} & {
readonly [Tag in Exclude<
keyof P,
Types.Tags<"_tag", I>
>]: never
}
>(
input: I,
fields: P
): Unify<ReturnType<P[keyof P]>>
}
Creates a match function for a specific value with discriminated union handling.
Details
This function provides a convenient way to pattern match on discriminated unions
by providing an object that maps each _tag value to its corresponding handler.
It's similar to a switch statement but with better type safety and exhaustiveness checking.
Example (Matching value tags)
import { Match } from "effect"
type Status = { readonly _tag: "Success"; readonly data: string }
const success: Status = { _tag: "Success", data: "Hello" }
// Simple valueTags usage
const message = Match.valueTags(success, {
Success: (result) => `Success: ${result.data}`
})
console.log(message) // "Success: Hello"
valueTags: {
<
const function (type parameter) I in <const I, P extends { readonly [Tag in Types.Tags<"_tag", I> & string]: (_: Extract<I, {
readonly _tag: Tag;
}>) => any; } & { readonly [Tag in Exclude<keyof P, Types.Tags<"_tag", I>>]: never; }>(fields: P): (input: I) => Unify<ReturnType<P[keyof P]>>
I,
function (type parameter) P in <const I, P extends { readonly [Tag in Types.Tags<"_tag", I> & string]: (_: Extract<I, {
readonly _tag: Tag;
}>) => any; } & { readonly [Tag in Exclude<keyof P, Types.Tags<"_tag", I>>]: never; }>(fields: P): (input: I) => Unify<ReturnType<P[keyof P]>>
P extends
& { readonly [function (type parameter) TagTag in Types.type Types.Tags<D extends string, P> = P extends Record<D, infer X> ? X : neverExtracts tag values from a discriminated union based on a discriminant field.
Details
This utility type extracts the possible values of a discriminant field
from a union type. It's used internally to implement tag-based pattern
matching for discriminated unions.
Example (Extracting discriminator tags)
import type { Match } from "effect"
type Events =
| { _tag: "click"; x: number; y: number }
| { _tag: "keypress"; key: string }
| { _tag: "scroll"; delta: number }
type EventTags = Match.Types.Tags<"_tag", Events>
// Result: "click" | "keypress" | "scroll"
type CustomTags = Match.Types.Tags<
"type",
| { type: "user"; name: string }
| { type: "admin"; permissions: Array<string> }
>
// Result: "user" | "admin"
Tags<"_tag", function (type parameter) I in <const I, P extends { readonly [Tag in Types.Tags<"_tag", I> & string]: (_: Extract<I, {
readonly _tag: Tag;
}>) => any; } & { readonly [Tag in Exclude<keyof P, Types.Tags<"_tag", I>>]: never; }>(fields: P): (input: I) => Unify<ReturnType<P[keyof P]>>
I> & string]: (_: Extract<
I,
{
readonly _tag: Tag
}
>
_: type Extract<T, U> = T extends U
? T
: never
Extract from T those types that are assignable to U
Extract<function (type parameter) I in <const I, P extends { readonly [Tag in Types.Tags<"_tag", I> & string]: (_: Extract<I, {
readonly _tag: Tag;
}>) => any; } & { readonly [Tag in Exclude<keyof P, Types.Tags<"_tag", I>>]: never; }>(fields: P): (input: I) => Unify<ReturnType<P[keyof P]>>
I, { readonly _tag: Tag extends Types.Tags<"_tag", I> & string_tag: function (type parameter) TagTag }>) => any }
& { readonly [function (type parameter) TagTag in type Exclude<T, U> = T extends U
? never
: T
Exclude from T those types that are assignable to U
Exclude<keyof function (type parameter) P in <const I, P extends { readonly [Tag in Types.Tags<"_tag", I> & string]: (_: Extract<I, {
readonly _tag: Tag;
}>) => any; } & { readonly [Tag in Exclude<keyof P, Types.Tags<"_tag", I>>]: never; }>(fields: P): (input: I) => Unify<ReturnType<P[keyof P]>>
P, Types.type Types.Tags<D extends string, P> = P extends Record<D, infer X> ? X : neverExtracts tag values from a discriminated union based on a discriminant field.
Details
This utility type extracts the possible values of a discriminant field
from a union type. It's used internally to implement tag-based pattern
matching for discriminated unions.
Example (Extracting discriminator tags)
import type { Match } from "effect"
type Events =
| { _tag: "click"; x: number; y: number }
| { _tag: "keypress"; key: string }
| { _tag: "scroll"; delta: number }
type EventTags = Match.Types.Tags<"_tag", Events>
// Result: "click" | "keypress" | "scroll"
type CustomTags = Match.Types.Tags<
"type",
| { type: "user"; name: string }
| { type: "admin"; permissions: Array<string> }
>
// Result: "user" | "admin"
Tags<"_tag", function (type parameter) I in <const I, P extends { readonly [Tag in Types.Tags<"_tag", I> & string]: (_: Extract<I, {
readonly _tag: Tag;
}>) => any; } & { readonly [Tag in Exclude<keyof P, Types.Tags<"_tag", I>>]: never; }>(fields: P): (input: I) => Unify<ReturnType<P[keyof P]>>
I>>]: never }
>(fields: P extends { readonly [Tag in Types.Tags<"_tag", I> & string]: (_: Extract<I, { readonly _tag: Tag; }>) => any; } & { readonly [Tag in Exclude<keyof P, Types.Tags<"_tag", I>>]: never; }fields: function (type parameter) P in <const I, P extends { readonly [Tag in Types.Tags<"_tag", I> & string]: (_: Extract<I, {
readonly _tag: Tag;
}>) => any; } & { readonly [Tag in Exclude<keyof P, Types.Tags<"_tag", I>>]: never; }>(fields: P): (input: I) => Unify<ReturnType<P[keyof P]>>
P): (input: const Iinput: function (type parameter) I in <const I, P extends { readonly [Tag in Types.Tags<"_tag", I> & string]: (_: Extract<I, {
readonly _tag: Tag;
}>) => any; } & { readonly [Tag in Exclude<keyof P, Types.Tags<"_tag", I>>]: never; }>(fields: P): (input: I) => Unify<ReturnType<P[keyof P]>>
I) => type Unify<A> = Values<ExtractTypes<FilterIn<A> & {
[typeSymbol]: A;
}>> extends infer Z ? Z | FilterInUnmatched<A, Keys<ExtractTypes<FilterIn<A> & {
[typeSymbol]: A;
}>>> | FilterOut<A> : never
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
Unify<type ReturnType<
T extends (...args: any) => any
> = T extends (...args: any) => infer R ? R : any
Obtain the return type of a function type
ReturnType<function (type parameter) P in <const I, P extends { readonly [Tag in Types.Tags<"_tag", I> & string]: (_: Extract<I, {
readonly _tag: Tag;
}>) => any; } & { readonly [Tag in Exclude<keyof P, Types.Tags<"_tag", I>>]: never; }>(fields: P): (input: I) => Unify<ReturnType<P[keyof P]>>
P[keyof function (type parameter) P in <const I, P extends { readonly [Tag in Types.Tags<"_tag", I> & string]: (_: Extract<I, {
readonly _tag: Tag;
}>) => any; } & { readonly [Tag in Exclude<keyof P, Types.Tags<"_tag", I>>]: never; }>(fields: P): (input: I) => Unify<ReturnType<P[keyof P]>>
P]>>
<
const function (type parameter) I in <const I, P extends { readonly [Tag in Types.Tags<"_tag", I> & string]: (_: Extract<I, {
readonly _tag: Tag;
}>) => any; } & { readonly [Tag in Exclude<keyof P, Types.Tags<"_tag", I>>]: never; }>(input: I, fields: P): Unify<ReturnType<P[keyof P]>>
I,
function (type parameter) P in <const I, P extends { readonly [Tag in Types.Tags<"_tag", I> & string]: (_: Extract<I, {
readonly _tag: Tag;
}>) => any; } & { readonly [Tag in Exclude<keyof P, Types.Tags<"_tag", I>>]: never; }>(input: I, fields: P): Unify<ReturnType<P[keyof P]>>
P extends
& { readonly [function (type parameter) TagTag in Types.type Types.Tags<D extends string, P> = P extends Record<D, infer X> ? X : neverExtracts tag values from a discriminated union based on a discriminant field.
Details
This utility type extracts the possible values of a discriminant field
from a union type. It's used internally to implement tag-based pattern
matching for discriminated unions.
Example (Extracting discriminator tags)
import type { Match } from "effect"
type Events =
| { _tag: "click"; x: number; y: number }
| { _tag: "keypress"; key: string }
| { _tag: "scroll"; delta: number }
type EventTags = Match.Types.Tags<"_tag", Events>
// Result: "click" | "keypress" | "scroll"
type CustomTags = Match.Types.Tags<
"type",
| { type: "user"; name: string }
| { type: "admin"; permissions: Array<string> }
>
// Result: "user" | "admin"
Tags<"_tag", function (type parameter) I in <const I, P extends { readonly [Tag in Types.Tags<"_tag", I> & string]: (_: Extract<I, {
readonly _tag: Tag;
}>) => any; } & { readonly [Tag in Exclude<keyof P, Types.Tags<"_tag", I>>]: never; }>(input: I, fields: P): Unify<ReturnType<P[keyof P]>>
I> & string]: (_: Extract<
I,
{
readonly _tag: Tag
}
>
_: type Extract<T, U> = T extends U
? T
: never
Extract from T those types that are assignable to U
Extract<function (type parameter) I in <const I, P extends { readonly [Tag in Types.Tags<"_tag", I> & string]: (_: Extract<I, {
readonly _tag: Tag;
}>) => any; } & { readonly [Tag in Exclude<keyof P, Types.Tags<"_tag", I>>]: never; }>(input: I, fields: P): Unify<ReturnType<P[keyof P]>>
I, { readonly _tag: Tag extends Types.Tags<"_tag", I> & string_tag: function (type parameter) TagTag }>) => any }
& { readonly [function (type parameter) TagTag in type Exclude<T, U> = T extends U
? never
: T
Exclude from T those types that are assignable to U
Exclude<keyof function (type parameter) P in <const I, P extends { readonly [Tag in Types.Tags<"_tag", I> & string]: (_: Extract<I, {
readonly _tag: Tag;
}>) => any; } & { readonly [Tag in Exclude<keyof P, Types.Tags<"_tag", I>>]: never; }>(input: I, fields: P): Unify<ReturnType<P[keyof P]>>
P, Types.type Types.Tags<D extends string, P> = P extends Record<D, infer X> ? X : neverExtracts tag values from a discriminated union based on a discriminant field.
Details
This utility type extracts the possible values of a discriminant field
from a union type. It's used internally to implement tag-based pattern
matching for discriminated unions.
Example (Extracting discriminator tags)
import type { Match } from "effect"
type Events =
| { _tag: "click"; x: number; y: number }
| { _tag: "keypress"; key: string }
| { _tag: "scroll"; delta: number }
type EventTags = Match.Types.Tags<"_tag", Events>
// Result: "click" | "keypress" | "scroll"
type CustomTags = Match.Types.Tags<
"type",
| { type: "user"; name: string }
| { type: "admin"; permissions: Array<string> }
>
// Result: "user" | "admin"
Tags<"_tag", function (type parameter) I in <const I, P extends { readonly [Tag in Types.Tags<"_tag", I> & string]: (_: Extract<I, {
readonly _tag: Tag;
}>) => any; } & { readonly [Tag in Exclude<keyof P, Types.Tags<"_tag", I>>]: never; }>(input: I, fields: P): Unify<ReturnType<P[keyof P]>>
I>>]: never }
>(input: const Iinput: function (type parameter) I in <const I, P extends { readonly [Tag in Types.Tags<"_tag", I> & string]: (_: Extract<I, {
readonly _tag: Tag;
}>) => any; } & { readonly [Tag in Exclude<keyof P, Types.Tags<"_tag", I>>]: never; }>(input: I, fields: P): Unify<ReturnType<P[keyof P]>>
I, fields: P extends { readonly [Tag in Types.Tags<"_tag", I> & string]: (_: Extract<I, { readonly _tag: Tag; }>) => any; } & { readonly [Tag in Exclude<keyof P, Types.Tags<"_tag", I>>]: never; }fields: function (type parameter) P in <const I, P extends { readonly [Tag in Types.Tags<"_tag", I> & string]: (_: Extract<I, {
readonly _tag: Tag;
}>) => any; } & { readonly [Tag in Exclude<keyof P, Types.Tags<"_tag", I>>]: never; }>(input: I, fields: P): Unify<ReturnType<P[keyof P]>>
P): type Unify<A> = Values<ExtractTypes<FilterIn<A> & {
[typeSymbol]: A;
}>> extends infer Z ? Z | FilterInUnmatched<A, Keys<ExtractTypes<FilterIn<A> & {
[typeSymbol]: A;
}>>> | FilterOut<A> : never
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
Unify<type ReturnType<
T extends (...args: any) => any
> = T extends (...args: any) => infer R ? R : any
Obtain the return type of a function type
ReturnType<function (type parameter) P in <const I, P extends { readonly [Tag in Types.Tags<"_tag", I> & string]: (_: Extract<I, {
readonly _tag: Tag;
}>) => any; } & { readonly [Tag in Exclude<keyof P, Types.Tags<"_tag", I>>]: never; }>(input: I, fields: P): Unify<ReturnType<P[keyof P]>>
P[keyof function (type parameter) P in <const I, P extends { readonly [Tag in Types.Tags<"_tag", I> & string]: (_: Extract<I, {
readonly _tag: Tag;
}>) => any; } & { readonly [Tag in Exclude<keyof P, Types.Tags<"_tag", I>>]: never; }>(input: I, fields: P): Unify<ReturnType<P[keyof P]>>
P]>>
} = import internalinternal.const valueTags: {
<
I,
P extends {
readonly [Tag in Types.Tags<"_tag", I> &
string]: (
_: Extract<
I,
{
readonly _tag: Tag
}
>
) => any
} & {
readonly [Tag in Exclude<
keyof P,
Types.Tags<"_tag", I>
>]: never
}
>(
fields: P
): (input: I) => Unify<ReturnType<P[keyof P]>>
<
I,
P extends {
readonly [Tag in Types.Tags<"_tag", I> &
string]: (
_: Extract<
I,
{
readonly _tag: Tag
}
>
) => any
} & {
readonly [Tag in Exclude<
keyof P,
Types.Tags<"_tag", I>
>]: never
}
>(
input: I,
fields: P
): Unify<ReturnType<P[keyof P]>>
}
valueTags