<Z extends TaggedEnum.WithGenerics<1>>(): Types.Simplify<
{
readonly [Tag in Z["taggedEnum"]["_tag"]]: <A>(
args: TaggedEnum.Args<
TaggedEnum.Kind<Z, A>,
Tag,
Extract<TaggedEnum.Kind<Z, A>, { readonly _tag: Tag }>
>
) => TaggedEnum.Value<TaggedEnum.Kind<Z, A>, Tag>
} & TaggedEnum.GenericMatchers<Z>
>
<Z extends TaggedEnum.WithGenerics<2>>(): Types.Simplify<
{
readonly [Tag in Z["taggedEnum"]["_tag"]]: <A, B>(
args: TaggedEnum.Args<
TaggedEnum.Kind<Z, A, B>,
Tag,
Extract<TaggedEnum.Kind<Z, A, B>, { readonly _tag: Tag }>
>
) => TaggedEnum.Value<TaggedEnum.Kind<Z, A, B>, Tag>
} & TaggedEnum.GenericMatchers<Z>
>
<Z extends TaggedEnum.WithGenerics<3>>(): Types.Simplify<
{
readonly [Tag in Z["taggedEnum"]["_tag"]]: <A, B, C>(
args: TaggedEnum.Args<
TaggedEnum.Kind<Z, A, B, C>,
Tag,
Extract<TaggedEnum.Kind<Z, A, B, C>, { readonly _tag: Tag }>
>
) => TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C>, Tag>
} & TaggedEnum.GenericMatchers<Z>
>
<Z extends TaggedEnum.WithGenerics<4>>(): Types.Simplify<
{
readonly [Tag in Z["taggedEnum"]["_tag"]]: <A, B, C, D>(
args: TaggedEnum.Args<
TaggedEnum.Kind<Z, A, B, C, D>,
Tag,
Extract<TaggedEnum.Kind<Z, A, B, C, D>, { readonly _tag: Tag }>
>
) => TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C, D>, Tag>
} & TaggedEnum.GenericMatchers<Z>
>
<A extends { readonly _tag: string }>(): TaggedEnum.Constructor<A>Creates constructors and matchers for a TaggedEnum type.
When to use
Use when you model a closed union with plain data objects and want construction, tag checks, and exhaustive matching from the same definition.
Details
Returns an object with:
- One constructor per variant (keyed by tag name)
$is(tag)— returns a type-guard function that checks only the_tagfield$match— exhaustive pattern matching (data-first or data-last)
Gotchas
- Constructors produce plain objects, not class instances.
$is(tag)only checks the_tagfield, not the full structure. It relies on the tag being globally unique and the value being produced by your constructors. For untrusted input, validate with theSchemamodule first.
Example (Creating and matching tagged enum values)
import { Data } from "effect"
type HttpError = Data.TaggedEnum<{
BadRequest: { readonly message: string }
NotFound: { readonly url: string }
}>
const { BadRequest, NotFound, $is, $match } = Data.taggedEnum<HttpError>()
const err = NotFound({ url: "/missing" })
// Type guard
console.log($is("NotFound")(err)) // true
// Pattern matching
const msg = $match(err, {
BadRequest: (e) => e.message,
NotFound: (e) => `${e.url} not found`
})
console.log(msg) // "/missing not found"Example (Defining a generic tagged enum)
import { Data } from "effect"
type MyResult<E, A> = Data.TaggedEnum<{
Failure: { readonly error: E }
Success: { readonly value: A }
}>
interface MyResultDef extends Data.TaggedEnum.WithGenerics<2> {
readonly taggedEnum: MyResult<this["A"], this["B"]>
}
const { Failure, Success } = Data.taggedEnum<MyResultDef>()
const ok = Success({ value: 42 })
// ok: { readonly _tag: "Success"; readonly value: number }export const const taggedEnum: {
<
Z extends TaggedEnum.WithGenerics<1>
>(): Types.Simplify<
{
readonly [Tag in Z["taggedEnum"]["_tag"]]: <
A
>(
args: TaggedEnum.Args<
TaggedEnum.Kind<Z, A>,
Tag,
Extract<
TaggedEnum.Kind<Z, A>,
{
readonly _tag: Tag
}
>
>
) => TaggedEnum.Value<
TaggedEnum.Kind<Z, A>,
Tag
>
} & TaggedEnum.GenericMatchers<Z>
>
<
Z extends TaggedEnum.WithGenerics<2>
>(): Types.Simplify<
{
readonly [Tag in Z["taggedEnum"]["_tag"]]: <
A,
B
>(
args: TaggedEnum.Args<
TaggedEnum.Kind<Z, A, B>,
Tag,
Extract<
TaggedEnum.Kind<Z, A, B>,
{
readonly _tag: Tag
}
>
>
) => TaggedEnum.Value<
TaggedEnum.Kind<Z, A, B>,
Tag
>
} & TaggedEnum.GenericMatchers<Z>
>
<
Z extends TaggedEnum.WithGenerics<3>
>(): Types.Simplify<
{
readonly [Tag in Z["taggedEnum"]["_tag"]]: <
A,
B,
C
>(
args: TaggedEnum.Args<
TaggedEnum.Kind<Z, A, B, C>,
Tag,
Extract<
TaggedEnum.Kind<Z, A, B, C>,
{
readonly _tag: Tag
}
>
>
) => TaggedEnum.Value<
TaggedEnum.Kind<Z, A, B, C>,
Tag
>
} & TaggedEnum.GenericMatchers<Z>
>
<
Z extends TaggedEnum.WithGenerics<4>
>(): Types.Simplify<
{
readonly [Tag in Z["taggedEnum"]["_tag"]]: <
A,
B,
C,
D
>(
args: TaggedEnum.Args<
TaggedEnum.Kind<Z, A, B, C, D>,
Tag,
Extract<
TaggedEnum.Kind<Z, A, B, C, D>,
{
readonly _tag: Tag
}
>
>
) => TaggedEnum.Value<
TaggedEnum.Kind<Z, A, B, C, D>,
Tag
>
} & TaggedEnum.GenericMatchers<Z>
>
<
A extends { readonly _tag: string }
>(): TaggedEnum.Constructor<A>
}
Creates constructors and matchers for a TaggedEnum type.
When to use
Use when you model a closed union with plain data objects and want
construction, tag checks, and exhaustive matching from the same definition.
Details
Returns an object with:
- One constructor per variant (keyed by tag name)
$is(tag) — returns a type-guard function that checks only the _tag field
$match — exhaustive pattern matching (data-first or data-last)
Gotchas
- Constructors produce plain objects, not class instances.
$is(tag) only checks the _tag field, not the full structure. It relies
on the tag being globally unique and the value being produced by your
constructors. For untrusted input, validate with the Schema module first.
Example (Creating and matching tagged enum values)
import { Data } from "effect"
type HttpError = Data.TaggedEnum<{
BadRequest: { readonly message: string }
NotFound: { readonly url: string }
}>
const { BadRequest, NotFound, $is, $match } = Data.taggedEnum<HttpError>()
const err = NotFound({ url: "/missing" })
// Type guard
console.log($is("NotFound")(err)) // true
// Pattern matching
const msg = $match(err, {
BadRequest: (e) => e.message,
NotFound: (e) => `${e.url} not found`
})
console.log(msg) // "/missing not found"
Example (Defining a generic tagged enum)
import { Data } from "effect"
type MyResult<E, A> = Data.TaggedEnum<{
Failure: { readonly error: E }
Success: { readonly value: A }
}>
interface MyResultDef extends Data.TaggedEnum.WithGenerics<2> {
readonly taggedEnum: MyResult<this["A"], this["B"]>
}
const { Failure, Success } = Data.taggedEnum<MyResultDef>()
const ok = Success({ value: 42 })
// ok: { readonly _tag: "Success"; readonly value: number }
taggedEnum: {
<function (type parameter) Z in <Z extends TaggedEnum.WithGenerics<1>>(): Types.Simplify<{ readonly [Tag in Z["taggedEnum"]["_tag"]]: <A>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A>, Tag, Extract<TaggedEnum.Kind<Z, A>, {
readonly _tag: Tag;
}>>) => TaggedEnum.Value<TaggedEnum.Kind<Z, A>, Tag>; } & TaggedEnum.GenericMatchers<Z>>
Z extends TaggedEnum.interface TaggedEnum<A extends Record<string, Record<string, any>> & UntaggedChildren<A>>.WithGenerics<Count extends number>Defines a tagged enum shape that accepts generic type parameters.
When to use
Use when variant payloads need to be parameterized, such as Result<E, A>.
Details
Extend this interface and set taggedEnum to your union type, using
this["A"], this["B"], etc. as placeholders for the generics. The
Count parameter declares how many generics are used (up to 4).
Example (Defining a generic tagged enum)
import { Data } from "effect"
type MyResult<E, A> = Data.TaggedEnum<{
Failure: { readonly error: E }
Success: { readonly value: A }
}>
interface MyResultDef extends Data.TaggedEnum.WithGenerics<2> {
readonly taggedEnum: MyResult<this["A"], this["B"]>
}
const { Failure, Success } = Data.taggedEnum<MyResultDef>()
const ok = Success({ value: 42 })
// ok: { readonly _tag: "Success"; readonly value: number }
WithGenerics<1>>(): import TypesTypes.type Simplify<A> = {
[K in keyof A]: A[K]
} extends infer B
? B
: never
Flattens an intersection type into a single object type for readability.
When to use
Use to clean up IDE tooltips that show A & B & C instead of a merged
object.
Details
Does not change the type semantically, only its display.
Example (Simplifying an intersection)
import type { Types } from "effect"
// Without Simplify: IDE shows { a: number } & { b: string }
// With Simplify: IDE shows { a: number; b: string }
type Clean = Types.Simplify<{ a: number } & { b: string }>
Simplify<
{
readonly [function (type parameter) TagTag in function (type parameter) Z in <Z extends TaggedEnum.WithGenerics<1>>(): Types.Simplify<{ readonly [Tag in Z["taggedEnum"]["_tag"]]: <A>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A>, Tag, Extract<TaggedEnum.Kind<Z, A>, {
readonly _tag: Tag;
}>>) => TaggedEnum.Value<TaggedEnum.Kind<Z, A>, Tag>; } & TaggedEnum.GenericMatchers<Z>>
Z["taggedEnum"]["_tag"]]: <function (type parameter) A in <A>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A>, Tag, Extract<TaggedEnum.Kind<Z, A>, {
readonly _tag: Tag;
}>>): TaggedEnum.Value<TaggedEnum.Kind<Z, A>, Tag>
A>(
args: TaggedEnum.Args<
TaggedEnum.Kind<
Z,
A,
unknown,
unknown,
unknown
>,
Tag,
Extract<
TaggedEnum.Kind<
Z,
A,
unknown,
unknown,
unknown
>,
{
readonly _tag: Tag
}
>
>
args: TaggedEnum.type TaggedEnum<A extends Record<string, Record<string, any>> & UntaggedChildren<A>>.Args<A extends { readonly _tag: string; }, K extends A["_tag"], E = Extract<A, { readonly _tag: K; }>> = { readonly [K in keyof E as K extends "_tag" ? never : K]: E[K]; } extends infer T ? Types.VoidIfEmpty<T> : neverExtracts the constructor argument type for a specific variant of a tagged
union.
When to use
Use to derive the argument object expected by a constructor for one tagged
union variant.
Details
Returns void if the variant has no fields beyond _tag.
Example (Extracting variant args)
import type { Data } from "effect"
type Result =
| { readonly _tag: "Ok"; readonly value: number }
| { readonly _tag: "Err"; readonly error: string }
type OkArgs = Data.TaggedEnum.Args<Result, "Ok">
// { readonly value: number }
type ErrArgs = Data.TaggedEnum.Args<Result, "Err">
// { readonly error: string }
Args<
TaggedEnum.type TaggedEnum<A extends Record<string, Record<string, any>> & UntaggedChildren<A>>.Kind<Z extends TaggedEnum.WithGenerics<number>, A = unknown, B = unknown, C = unknown, D = unknown> = (Z & {
readonly A: A;
readonly B: B;
readonly C: C;
readonly D: D;
})["taggedEnum"]
Applies concrete type arguments to a WithGenerics definition, producing
the resulting tagged union type.
When to use
Use to refer to a specific instantiation of a generic tagged enum in type signatures.
Example (Applying generics)
import type { Data } from "effect"
type Option<A> = Data.TaggedEnum<{
None: {}
Some: { readonly value: A }
}>
interface OptionDef extends Data.TaggedEnum.WithGenerics<1> {
readonly taggedEnum: Option<this["A"]>
}
// Resolve to the concrete union for `string`
type StringOption = Data.TaggedEnum.Kind<OptionDef, string>
// { _tag: "None" } | { _tag: "Some"; value: string }
Kind<function (type parameter) Z in <Z extends TaggedEnum.WithGenerics<1>>(): Types.Simplify<{ readonly [Tag in Z["taggedEnum"]["_tag"]]: <A>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A>, Tag, Extract<TaggedEnum.Kind<Z, A>, {
readonly _tag: Tag;
}>>) => TaggedEnum.Value<TaggedEnum.Kind<Z, A>, Tag>; } & TaggedEnum.GenericMatchers<Z>>
Z, function (type parameter) A in <A>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A>, Tag, Extract<TaggedEnum.Kind<Z, A>, {
readonly _tag: Tag;
}>>): TaggedEnum.Value<TaggedEnum.Kind<Z, A>, Tag>
A>,
function (type parameter) TagTag,
type Extract<T, U> = T extends U
? T
: never
Extract from T those types that are assignable to U
Extract<TaggedEnum.type TaggedEnum<A extends Record<string, Record<string, any>> & UntaggedChildren<A>>.Kind<Z extends TaggedEnum.WithGenerics<number>, A = unknown, B = unknown, C = unknown, D = unknown> = (Z & {
readonly A: A;
readonly B: B;
readonly C: C;
readonly D: D;
})["taggedEnum"]
Applies concrete type arguments to a WithGenerics definition, producing
the resulting tagged union type.
When to use
Use to refer to a specific instantiation of a generic tagged enum in type signatures.
Example (Applying generics)
import type { Data } from "effect"
type Option<A> = Data.TaggedEnum<{
None: {}
Some: { readonly value: A }
}>
interface OptionDef extends Data.TaggedEnum.WithGenerics<1> {
readonly taggedEnum: Option<this["A"]>
}
// Resolve to the concrete union for `string`
type StringOption = Data.TaggedEnum.Kind<OptionDef, string>
// { _tag: "None" } | { _tag: "Some"; value: string }
Kind<function (type parameter) Z in <Z extends TaggedEnum.WithGenerics<1>>(): Types.Simplify<{ readonly [Tag in Z["taggedEnum"]["_tag"]]: <A>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A>, Tag, Extract<TaggedEnum.Kind<Z, A>, {
readonly _tag: Tag;
}>>) => TaggedEnum.Value<TaggedEnum.Kind<Z, A>, Tag>; } & TaggedEnum.GenericMatchers<Z>>
Z, function (type parameter) A in <A>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A>, Tag, Extract<TaggedEnum.Kind<Z, A>, {
readonly _tag: Tag;
}>>): TaggedEnum.Value<TaggedEnum.Kind<Z, A>, Tag>
A>, { readonly _tag: Tag extends Z["taggedEnum"]["_tag"]_tag: function (type parameter) TagTag }>
>
) => TaggedEnum.type TaggedEnum<A extends Record<string, Record<string, any>> & UntaggedChildren<A>>.Value<A extends { readonly _tag: string; }, K extends A["_tag"]> = A extends {
readonly _tag: K;
} ? A : never
Extracts the full variant type (including _tag) for a specific tag.
When to use
Use to select one full tagged-union variant by its _tag value.
Example (Extracting a variant type)
import type { Data } from "effect"
type Result =
| { readonly _tag: "Ok"; readonly value: number }
| { readonly _tag: "Err"; readonly error: string }
type OkVariant = Data.TaggedEnum.Value<Result, "Ok">
// { readonly _tag: "Ok"; readonly value: number }
Value<TaggedEnum.type TaggedEnum<A extends Record<string, Record<string, any>> & UntaggedChildren<A>>.Kind<Z extends TaggedEnum.WithGenerics<number>, A = unknown, B = unknown, C = unknown, D = unknown> = (Z & {
readonly A: A;
readonly B: B;
readonly C: C;
readonly D: D;
})["taggedEnum"]
Applies concrete type arguments to a WithGenerics definition, producing
the resulting tagged union type.
When to use
Use to refer to a specific instantiation of a generic tagged enum in type signatures.
Example (Applying generics)
import type { Data } from "effect"
type Option<A> = Data.TaggedEnum<{
None: {}
Some: { readonly value: A }
}>
interface OptionDef extends Data.TaggedEnum.WithGenerics<1> {
readonly taggedEnum: Option<this["A"]>
}
// Resolve to the concrete union for `string`
type StringOption = Data.TaggedEnum.Kind<OptionDef, string>
// { _tag: "None" } | { _tag: "Some"; value: string }
Kind<function (type parameter) Z in <Z extends TaggedEnum.WithGenerics<1>>(): Types.Simplify<{ readonly [Tag in Z["taggedEnum"]["_tag"]]: <A>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A>, Tag, Extract<TaggedEnum.Kind<Z, A>, {
readonly _tag: Tag;
}>>) => TaggedEnum.Value<TaggedEnum.Kind<Z, A>, Tag>; } & TaggedEnum.GenericMatchers<Z>>
Z, function (type parameter) A in <A>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A>, Tag, Extract<TaggedEnum.Kind<Z, A>, {
readonly _tag: Tag;
}>>): TaggedEnum.Value<TaggedEnum.Kind<Z, A>, Tag>
A>, function (type parameter) TagTag>
} & TaggedEnum.interface TaggedEnum<A extends Record<string, Record<string, any>> & UntaggedChildren<A>>.GenericMatchers<Z extends TaggedEnum.WithGenerics<number>>Type-guard and pattern-matching interface for generic tagged enums.
When to use
Use to type the $is and $match helpers for generic tagged enums.
Details
This is the $is / $match portion of the object returned by
taggedEnum
when used with a
WithGenerics
definition.
GenericMatchers<function (type parameter) Z in <Z extends TaggedEnum.WithGenerics<1>>(): Types.Simplify<{ readonly [Tag in Z["taggedEnum"]["_tag"]]: <A>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A>, Tag, Extract<TaggedEnum.Kind<Z, A>, {
readonly _tag: Tag;
}>>) => TaggedEnum.Value<TaggedEnum.Kind<Z, A>, Tag>; } & TaggedEnum.GenericMatchers<Z>>
Z>
>
<function (type parameter) Z in <Z extends TaggedEnum.WithGenerics<2>>(): Types.Simplify<{ readonly [Tag in Z["taggedEnum"]["_tag"]]: <A, B>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B>, Tag, Extract<TaggedEnum.Kind<Z, A, B>, {
readonly _tag: Tag;
}>>) => TaggedEnum.Value<TaggedEnum.Kind<Z, A, B>, Tag>; } & TaggedEnum.GenericMatchers<Z>>
Z extends TaggedEnum.interface TaggedEnum<A extends Record<string, Record<string, any>> & UntaggedChildren<A>>.WithGenerics<Count extends number>Defines a tagged enum shape that accepts generic type parameters.
When to use
Use when variant payloads need to be parameterized, such as Result<E, A>.
Details
Extend this interface and set taggedEnum to your union type, using
this["A"], this["B"], etc. as placeholders for the generics. The
Count parameter declares how many generics are used (up to 4).
Example (Defining a generic tagged enum)
import { Data } from "effect"
type MyResult<E, A> = Data.TaggedEnum<{
Failure: { readonly error: E }
Success: { readonly value: A }
}>
interface MyResultDef extends Data.TaggedEnum.WithGenerics<2> {
readonly taggedEnum: MyResult<this["A"], this["B"]>
}
const { Failure, Success } = Data.taggedEnum<MyResultDef>()
const ok = Success({ value: 42 })
// ok: { readonly _tag: "Success"; readonly value: number }
WithGenerics<2>>(): import TypesTypes.type Simplify<A> = {
[K in keyof A]: A[K]
} extends infer B
? B
: never
Flattens an intersection type into a single object type for readability.
When to use
Use to clean up IDE tooltips that show A & B & C instead of a merged
object.
Details
Does not change the type semantically, only its display.
Example (Simplifying an intersection)
import type { Types } from "effect"
// Without Simplify: IDE shows { a: number } & { b: string }
// With Simplify: IDE shows { a: number; b: string }
type Clean = Types.Simplify<{ a: number } & { b: string }>
Simplify<
{
readonly [function (type parameter) TagTag in function (type parameter) Z in <Z extends TaggedEnum.WithGenerics<2>>(): Types.Simplify<{ readonly [Tag in Z["taggedEnum"]["_tag"]]: <A, B>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B>, Tag, Extract<TaggedEnum.Kind<Z, A, B>, {
readonly _tag: Tag;
}>>) => TaggedEnum.Value<TaggedEnum.Kind<Z, A, B>, Tag>; } & TaggedEnum.GenericMatchers<Z>>
Z["taggedEnum"]["_tag"]]: <function (type parameter) A in <A, B>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B>, Tag, Extract<TaggedEnum.Kind<Z, A, B>, {
readonly _tag: Tag;
}>>): TaggedEnum.Value<TaggedEnum.Kind<Z, A, B>, Tag>
A, function (type parameter) B in <A, B>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B>, Tag, Extract<TaggedEnum.Kind<Z, A, B>, {
readonly _tag: Tag;
}>>): TaggedEnum.Value<TaggedEnum.Kind<Z, A, B>, Tag>
B>(
args: TaggedEnum.Args<
TaggedEnum.Kind<Z, A, B, unknown, unknown>,
Tag,
Extract<
TaggedEnum.Kind<Z, A, B, unknown, unknown>,
{
readonly _tag: Tag
}
>
>
args: TaggedEnum.type TaggedEnum<A extends Record<string, Record<string, any>> & UntaggedChildren<A>>.Args<A extends { readonly _tag: string; }, K extends A["_tag"], E = Extract<A, { readonly _tag: K; }>> = { readonly [K in keyof E as K extends "_tag" ? never : K]: E[K]; } extends infer T ? Types.VoidIfEmpty<T> : neverExtracts the constructor argument type for a specific variant of a tagged
union.
When to use
Use to derive the argument object expected by a constructor for one tagged
union variant.
Details
Returns void if the variant has no fields beyond _tag.
Example (Extracting variant args)
import type { Data } from "effect"
type Result =
| { readonly _tag: "Ok"; readonly value: number }
| { readonly _tag: "Err"; readonly error: string }
type OkArgs = Data.TaggedEnum.Args<Result, "Ok">
// { readonly value: number }
type ErrArgs = Data.TaggedEnum.Args<Result, "Err">
// { readonly error: string }
Args<
TaggedEnum.type TaggedEnum<A extends Record<string, Record<string, any>> & UntaggedChildren<A>>.Kind<Z extends TaggedEnum.WithGenerics<number>, A = unknown, B = unknown, C = unknown, D = unknown> = (Z & {
readonly A: A;
readonly B: B;
readonly C: C;
readonly D: D;
})["taggedEnum"]
Applies concrete type arguments to a WithGenerics definition, producing
the resulting tagged union type.
When to use
Use to refer to a specific instantiation of a generic tagged enum in type signatures.
Example (Applying generics)
import type { Data } from "effect"
type Option<A> = Data.TaggedEnum<{
None: {}
Some: { readonly value: A }
}>
interface OptionDef extends Data.TaggedEnum.WithGenerics<1> {
readonly taggedEnum: Option<this["A"]>
}
// Resolve to the concrete union for `string`
type StringOption = Data.TaggedEnum.Kind<OptionDef, string>
// { _tag: "None" } | { _tag: "Some"; value: string }
Kind<function (type parameter) Z in <Z extends TaggedEnum.WithGenerics<2>>(): Types.Simplify<{ readonly [Tag in Z["taggedEnum"]["_tag"]]: <A, B>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B>, Tag, Extract<TaggedEnum.Kind<Z, A, B>, {
readonly _tag: Tag;
}>>) => TaggedEnum.Value<TaggedEnum.Kind<Z, A, B>, Tag>; } & TaggedEnum.GenericMatchers<Z>>
Z, function (type parameter) A in <A, B>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B>, Tag, Extract<TaggedEnum.Kind<Z, A, B>, {
readonly _tag: Tag;
}>>): TaggedEnum.Value<TaggedEnum.Kind<Z, A, B>, Tag>
A, function (type parameter) B in <A, B>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B>, Tag, Extract<TaggedEnum.Kind<Z, A, B>, {
readonly _tag: Tag;
}>>): TaggedEnum.Value<TaggedEnum.Kind<Z, A, B>, Tag>
B>,
function (type parameter) TagTag,
type Extract<T, U> = T extends U
? T
: never
Extract from T those types that are assignable to U
Extract<TaggedEnum.type TaggedEnum<A extends Record<string, Record<string, any>> & UntaggedChildren<A>>.Kind<Z extends TaggedEnum.WithGenerics<number>, A = unknown, B = unknown, C = unknown, D = unknown> = (Z & {
readonly A: A;
readonly B: B;
readonly C: C;
readonly D: D;
})["taggedEnum"]
Applies concrete type arguments to a WithGenerics definition, producing
the resulting tagged union type.
When to use
Use to refer to a specific instantiation of a generic tagged enum in type signatures.
Example (Applying generics)
import type { Data } from "effect"
type Option<A> = Data.TaggedEnum<{
None: {}
Some: { readonly value: A }
}>
interface OptionDef extends Data.TaggedEnum.WithGenerics<1> {
readonly taggedEnum: Option<this["A"]>
}
// Resolve to the concrete union for `string`
type StringOption = Data.TaggedEnum.Kind<OptionDef, string>
// { _tag: "None" } | { _tag: "Some"; value: string }
Kind<function (type parameter) Z in <Z extends TaggedEnum.WithGenerics<2>>(): Types.Simplify<{ readonly [Tag in Z["taggedEnum"]["_tag"]]: <A, B>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B>, Tag, Extract<TaggedEnum.Kind<Z, A, B>, {
readonly _tag: Tag;
}>>) => TaggedEnum.Value<TaggedEnum.Kind<Z, A, B>, Tag>; } & TaggedEnum.GenericMatchers<Z>>
Z, function (type parameter) A in <A, B>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B>, Tag, Extract<TaggedEnum.Kind<Z, A, B>, {
readonly _tag: Tag;
}>>): TaggedEnum.Value<TaggedEnum.Kind<Z, A, B>, Tag>
A, function (type parameter) B in <A, B>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B>, Tag, Extract<TaggedEnum.Kind<Z, A, B>, {
readonly _tag: Tag;
}>>): TaggedEnum.Value<TaggedEnum.Kind<Z, A, B>, Tag>
B>, { readonly _tag: Tag extends Z["taggedEnum"]["_tag"]_tag: function (type parameter) TagTag }>
>
) => TaggedEnum.type TaggedEnum<A extends Record<string, Record<string, any>> & UntaggedChildren<A>>.Value<A extends { readonly _tag: string; }, K extends A["_tag"]> = A extends {
readonly _tag: K;
} ? A : never
Extracts the full variant type (including _tag) for a specific tag.
When to use
Use to select one full tagged-union variant by its _tag value.
Example (Extracting a variant type)
import type { Data } from "effect"
type Result =
| { readonly _tag: "Ok"; readonly value: number }
| { readonly _tag: "Err"; readonly error: string }
type OkVariant = Data.TaggedEnum.Value<Result, "Ok">
// { readonly _tag: "Ok"; readonly value: number }
Value<TaggedEnum.type TaggedEnum<A extends Record<string, Record<string, any>> & UntaggedChildren<A>>.Kind<Z extends TaggedEnum.WithGenerics<number>, A = unknown, B = unknown, C = unknown, D = unknown> = (Z & {
readonly A: A;
readonly B: B;
readonly C: C;
readonly D: D;
})["taggedEnum"]
Applies concrete type arguments to a WithGenerics definition, producing
the resulting tagged union type.
When to use
Use to refer to a specific instantiation of a generic tagged enum in type signatures.
Example (Applying generics)
import type { Data } from "effect"
type Option<A> = Data.TaggedEnum<{
None: {}
Some: { readonly value: A }
}>
interface OptionDef extends Data.TaggedEnum.WithGenerics<1> {
readonly taggedEnum: Option<this["A"]>
}
// Resolve to the concrete union for `string`
type StringOption = Data.TaggedEnum.Kind<OptionDef, string>
// { _tag: "None" } | { _tag: "Some"; value: string }
Kind<function (type parameter) Z in <Z extends TaggedEnum.WithGenerics<2>>(): Types.Simplify<{ readonly [Tag in Z["taggedEnum"]["_tag"]]: <A, B>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B>, Tag, Extract<TaggedEnum.Kind<Z, A, B>, {
readonly _tag: Tag;
}>>) => TaggedEnum.Value<TaggedEnum.Kind<Z, A, B>, Tag>; } & TaggedEnum.GenericMatchers<Z>>
Z, function (type parameter) A in <A, B>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B>, Tag, Extract<TaggedEnum.Kind<Z, A, B>, {
readonly _tag: Tag;
}>>): TaggedEnum.Value<TaggedEnum.Kind<Z, A, B>, Tag>
A, function (type parameter) B in <A, B>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B>, Tag, Extract<TaggedEnum.Kind<Z, A, B>, {
readonly _tag: Tag;
}>>): TaggedEnum.Value<TaggedEnum.Kind<Z, A, B>, Tag>
B>, function (type parameter) TagTag>
} & TaggedEnum.interface TaggedEnum<A extends Record<string, Record<string, any>> & UntaggedChildren<A>>.GenericMatchers<Z extends TaggedEnum.WithGenerics<number>>Type-guard and pattern-matching interface for generic tagged enums.
When to use
Use to type the $is and $match helpers for generic tagged enums.
Details
This is the $is / $match portion of the object returned by
taggedEnum
when used with a
WithGenerics
definition.
GenericMatchers<function (type parameter) Z in <Z extends TaggedEnum.WithGenerics<2>>(): Types.Simplify<{ readonly [Tag in Z["taggedEnum"]["_tag"]]: <A, B>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B>, Tag, Extract<TaggedEnum.Kind<Z, A, B>, {
readonly _tag: Tag;
}>>) => TaggedEnum.Value<TaggedEnum.Kind<Z, A, B>, Tag>; } & TaggedEnum.GenericMatchers<Z>>
Z>
>
<function (type parameter) Z in <Z extends TaggedEnum.WithGenerics<3>>(): Types.Simplify<{ readonly [Tag in Z["taggedEnum"]["_tag"]]: <A, B, C>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B, C>, Tag, Extract<TaggedEnum.Kind<Z, A, B, C>, {
readonly _tag: Tag;
}>>) => TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C>, Tag>; } & TaggedEnum.GenericMatchers<Z>>
Z extends TaggedEnum.interface TaggedEnum<A extends Record<string, Record<string, any>> & UntaggedChildren<A>>.WithGenerics<Count extends number>Defines a tagged enum shape that accepts generic type parameters.
When to use
Use when variant payloads need to be parameterized, such as Result<E, A>.
Details
Extend this interface and set taggedEnum to your union type, using
this["A"], this["B"], etc. as placeholders for the generics. The
Count parameter declares how many generics are used (up to 4).
Example (Defining a generic tagged enum)
import { Data } from "effect"
type MyResult<E, A> = Data.TaggedEnum<{
Failure: { readonly error: E }
Success: { readonly value: A }
}>
interface MyResultDef extends Data.TaggedEnum.WithGenerics<2> {
readonly taggedEnum: MyResult<this["A"], this["B"]>
}
const { Failure, Success } = Data.taggedEnum<MyResultDef>()
const ok = Success({ value: 42 })
// ok: { readonly _tag: "Success"; readonly value: number }
WithGenerics<3>>(): import TypesTypes.type Simplify<A> = {
[K in keyof A]: A[K]
} extends infer B
? B
: never
Flattens an intersection type into a single object type for readability.
When to use
Use to clean up IDE tooltips that show A & B & C instead of a merged
object.
Details
Does not change the type semantically, only its display.
Example (Simplifying an intersection)
import type { Types } from "effect"
// Without Simplify: IDE shows { a: number } & { b: string }
// With Simplify: IDE shows { a: number; b: string }
type Clean = Types.Simplify<{ a: number } & { b: string }>
Simplify<
{
readonly [function (type parameter) TagTag in function (type parameter) Z in <Z extends TaggedEnum.WithGenerics<3>>(): Types.Simplify<{ readonly [Tag in Z["taggedEnum"]["_tag"]]: <A, B, C>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B, C>, Tag, Extract<TaggedEnum.Kind<Z, A, B, C>, {
readonly _tag: Tag;
}>>) => TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C>, Tag>; } & TaggedEnum.GenericMatchers<Z>>
Z["taggedEnum"]["_tag"]]: <function (type parameter) A in <A, B, C>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B, C>, Tag, Extract<TaggedEnum.Kind<Z, A, B, C>, {
readonly _tag: Tag;
}>>): TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C>, Tag>
A, function (type parameter) B in <A, B, C>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B, C>, Tag, Extract<TaggedEnum.Kind<Z, A, B, C>, {
readonly _tag: Tag;
}>>): TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C>, Tag>
B, function (type parameter) C in <A, B, C>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B, C>, Tag, Extract<TaggedEnum.Kind<Z, A, B, C>, {
readonly _tag: Tag;
}>>): TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C>, Tag>
C>(
args: TaggedEnum.Args<
TaggedEnum.Kind<Z, A, B, C, unknown>,
Tag,
Extract<
TaggedEnum.Kind<Z, A, B, C, unknown>,
{
readonly _tag: Tag
}
>
>
args: TaggedEnum.type TaggedEnum<A extends Record<string, Record<string, any>> & UntaggedChildren<A>>.Args<A extends { readonly _tag: string; }, K extends A["_tag"], E = Extract<A, { readonly _tag: K; }>> = { readonly [K in keyof E as K extends "_tag" ? never : K]: E[K]; } extends infer T ? Types.VoidIfEmpty<T> : neverExtracts the constructor argument type for a specific variant of a tagged
union.
When to use
Use to derive the argument object expected by a constructor for one tagged
union variant.
Details
Returns void if the variant has no fields beyond _tag.
Example (Extracting variant args)
import type { Data } from "effect"
type Result =
| { readonly _tag: "Ok"; readonly value: number }
| { readonly _tag: "Err"; readonly error: string }
type OkArgs = Data.TaggedEnum.Args<Result, "Ok">
// { readonly value: number }
type ErrArgs = Data.TaggedEnum.Args<Result, "Err">
// { readonly error: string }
Args<
TaggedEnum.type TaggedEnum<A extends Record<string, Record<string, any>> & UntaggedChildren<A>>.Kind<Z extends TaggedEnum.WithGenerics<number>, A = unknown, B = unknown, C = unknown, D = unknown> = (Z & {
readonly A: A;
readonly B: B;
readonly C: C;
readonly D: D;
})["taggedEnum"]
Applies concrete type arguments to a WithGenerics definition, producing
the resulting tagged union type.
When to use
Use to refer to a specific instantiation of a generic tagged enum in type signatures.
Example (Applying generics)
import type { Data } from "effect"
type Option<A> = Data.TaggedEnum<{
None: {}
Some: { readonly value: A }
}>
interface OptionDef extends Data.TaggedEnum.WithGenerics<1> {
readonly taggedEnum: Option<this["A"]>
}
// Resolve to the concrete union for `string`
type StringOption = Data.TaggedEnum.Kind<OptionDef, string>
// { _tag: "None" } | { _tag: "Some"; value: string }
Kind<function (type parameter) Z in <Z extends TaggedEnum.WithGenerics<3>>(): Types.Simplify<{ readonly [Tag in Z["taggedEnum"]["_tag"]]: <A, B, C>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B, C>, Tag, Extract<TaggedEnum.Kind<Z, A, B, C>, {
readonly _tag: Tag;
}>>) => TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C>, Tag>; } & TaggedEnum.GenericMatchers<Z>>
Z, function (type parameter) A in <A, B, C>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B, C>, Tag, Extract<TaggedEnum.Kind<Z, A, B, C>, {
readonly _tag: Tag;
}>>): TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C>, Tag>
A, function (type parameter) B in <A, B, C>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B, C>, Tag, Extract<TaggedEnum.Kind<Z, A, B, C>, {
readonly _tag: Tag;
}>>): TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C>, Tag>
B, function (type parameter) C in <A, B, C>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B, C>, Tag, Extract<TaggedEnum.Kind<Z, A, B, C>, {
readonly _tag: Tag;
}>>): TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C>, Tag>
C>,
function (type parameter) TagTag,
type Extract<T, U> = T extends U
? T
: never
Extract from T those types that are assignable to U
Extract<TaggedEnum.type TaggedEnum<A extends Record<string, Record<string, any>> & UntaggedChildren<A>>.Kind<Z extends TaggedEnum.WithGenerics<number>, A = unknown, B = unknown, C = unknown, D = unknown> = (Z & {
readonly A: A;
readonly B: B;
readonly C: C;
readonly D: D;
})["taggedEnum"]
Applies concrete type arguments to a WithGenerics definition, producing
the resulting tagged union type.
When to use
Use to refer to a specific instantiation of a generic tagged enum in type signatures.
Example (Applying generics)
import type { Data } from "effect"
type Option<A> = Data.TaggedEnum<{
None: {}
Some: { readonly value: A }
}>
interface OptionDef extends Data.TaggedEnum.WithGenerics<1> {
readonly taggedEnum: Option<this["A"]>
}
// Resolve to the concrete union for `string`
type StringOption = Data.TaggedEnum.Kind<OptionDef, string>
// { _tag: "None" } | { _tag: "Some"; value: string }
Kind<function (type parameter) Z in <Z extends TaggedEnum.WithGenerics<3>>(): Types.Simplify<{ readonly [Tag in Z["taggedEnum"]["_tag"]]: <A, B, C>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B, C>, Tag, Extract<TaggedEnum.Kind<Z, A, B, C>, {
readonly _tag: Tag;
}>>) => TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C>, Tag>; } & TaggedEnum.GenericMatchers<Z>>
Z, function (type parameter) A in <A, B, C>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B, C>, Tag, Extract<TaggedEnum.Kind<Z, A, B, C>, {
readonly _tag: Tag;
}>>): TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C>, Tag>
A, function (type parameter) B in <A, B, C>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B, C>, Tag, Extract<TaggedEnum.Kind<Z, A, B, C>, {
readonly _tag: Tag;
}>>): TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C>, Tag>
B, function (type parameter) C in <A, B, C>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B, C>, Tag, Extract<TaggedEnum.Kind<Z, A, B, C>, {
readonly _tag: Tag;
}>>): TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C>, Tag>
C>, { readonly _tag: Tag extends Z["taggedEnum"]["_tag"]_tag: function (type parameter) TagTag }>
>
) => TaggedEnum.type TaggedEnum<A extends Record<string, Record<string, any>> & UntaggedChildren<A>>.Value<A extends { readonly _tag: string; }, K extends A["_tag"]> = A extends {
readonly _tag: K;
} ? A : never
Extracts the full variant type (including _tag) for a specific tag.
When to use
Use to select one full tagged-union variant by its _tag value.
Example (Extracting a variant type)
import type { Data } from "effect"
type Result =
| { readonly _tag: "Ok"; readonly value: number }
| { readonly _tag: "Err"; readonly error: string }
type OkVariant = Data.TaggedEnum.Value<Result, "Ok">
// { readonly _tag: "Ok"; readonly value: number }
Value<TaggedEnum.type TaggedEnum<A extends Record<string, Record<string, any>> & UntaggedChildren<A>>.Kind<Z extends TaggedEnum.WithGenerics<number>, A = unknown, B = unknown, C = unknown, D = unknown> = (Z & {
readonly A: A;
readonly B: B;
readonly C: C;
readonly D: D;
})["taggedEnum"]
Applies concrete type arguments to a WithGenerics definition, producing
the resulting tagged union type.
When to use
Use to refer to a specific instantiation of a generic tagged enum in type signatures.
Example (Applying generics)
import type { Data } from "effect"
type Option<A> = Data.TaggedEnum<{
None: {}
Some: { readonly value: A }
}>
interface OptionDef extends Data.TaggedEnum.WithGenerics<1> {
readonly taggedEnum: Option<this["A"]>
}
// Resolve to the concrete union for `string`
type StringOption = Data.TaggedEnum.Kind<OptionDef, string>
// { _tag: "None" } | { _tag: "Some"; value: string }
Kind<function (type parameter) Z in <Z extends TaggedEnum.WithGenerics<3>>(): Types.Simplify<{ readonly [Tag in Z["taggedEnum"]["_tag"]]: <A, B, C>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B, C>, Tag, Extract<TaggedEnum.Kind<Z, A, B, C>, {
readonly _tag: Tag;
}>>) => TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C>, Tag>; } & TaggedEnum.GenericMatchers<Z>>
Z, function (type parameter) A in <A, B, C>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B, C>, Tag, Extract<TaggedEnum.Kind<Z, A, B, C>, {
readonly _tag: Tag;
}>>): TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C>, Tag>
A, function (type parameter) B in <A, B, C>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B, C>, Tag, Extract<TaggedEnum.Kind<Z, A, B, C>, {
readonly _tag: Tag;
}>>): TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C>, Tag>
B, function (type parameter) C in <A, B, C>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B, C>, Tag, Extract<TaggedEnum.Kind<Z, A, B, C>, {
readonly _tag: Tag;
}>>): TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C>, Tag>
C>, function (type parameter) TagTag>
} & TaggedEnum.interface TaggedEnum<A extends Record<string, Record<string, any>> & UntaggedChildren<A>>.GenericMatchers<Z extends TaggedEnum.WithGenerics<number>>Type-guard and pattern-matching interface for generic tagged enums.
When to use
Use to type the $is and $match helpers for generic tagged enums.
Details
This is the $is / $match portion of the object returned by
taggedEnum
when used with a
WithGenerics
definition.
GenericMatchers<function (type parameter) Z in <Z extends TaggedEnum.WithGenerics<3>>(): Types.Simplify<{ readonly [Tag in Z["taggedEnum"]["_tag"]]: <A, B, C>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B, C>, Tag, Extract<TaggedEnum.Kind<Z, A, B, C>, {
readonly _tag: Tag;
}>>) => TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C>, Tag>; } & TaggedEnum.GenericMatchers<Z>>
Z>
>
<function (type parameter) Z in <Z extends TaggedEnum.WithGenerics<4>>(): Types.Simplify<{ readonly [Tag in Z["taggedEnum"]["_tag"]]: <A, B, C, D>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B, C, D>, Tag, Extract<TaggedEnum.Kind<Z, A, B, C, D>, {
readonly _tag: Tag;
}>>) => TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C, D>, Tag>; } & TaggedEnum.GenericMatchers<Z>>
Z extends TaggedEnum.interface TaggedEnum<A extends Record<string, Record<string, any>> & UntaggedChildren<A>>.WithGenerics<Count extends number>Defines a tagged enum shape that accepts generic type parameters.
When to use
Use when variant payloads need to be parameterized, such as Result<E, A>.
Details
Extend this interface and set taggedEnum to your union type, using
this["A"], this["B"], etc. as placeholders for the generics. The
Count parameter declares how many generics are used (up to 4).
Example (Defining a generic tagged enum)
import { Data } from "effect"
type MyResult<E, A> = Data.TaggedEnum<{
Failure: { readonly error: E }
Success: { readonly value: A }
}>
interface MyResultDef extends Data.TaggedEnum.WithGenerics<2> {
readonly taggedEnum: MyResult<this["A"], this["B"]>
}
const { Failure, Success } = Data.taggedEnum<MyResultDef>()
const ok = Success({ value: 42 })
// ok: { readonly _tag: "Success"; readonly value: number }
WithGenerics<4>>(): import TypesTypes.type Simplify<A> = {
[K in keyof A]: A[K]
} extends infer B
? B
: never
Flattens an intersection type into a single object type for readability.
When to use
Use to clean up IDE tooltips that show A & B & C instead of a merged
object.
Details
Does not change the type semantically, only its display.
Example (Simplifying an intersection)
import type { Types } from "effect"
// Without Simplify: IDE shows { a: number } & { b: string }
// With Simplify: IDE shows { a: number; b: string }
type Clean = Types.Simplify<{ a: number } & { b: string }>
Simplify<
{
readonly [function (type parameter) TagTag in function (type parameter) Z in <Z extends TaggedEnum.WithGenerics<4>>(): Types.Simplify<{ readonly [Tag in Z["taggedEnum"]["_tag"]]: <A, B, C, D>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B, C, D>, Tag, Extract<TaggedEnum.Kind<Z, A, B, C, D>, {
readonly _tag: Tag;
}>>) => TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C, D>, Tag>; } & TaggedEnum.GenericMatchers<Z>>
Z["taggedEnum"]["_tag"]]: <function (type parameter) A in <A, B, C, D>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B, C, D>, Tag, Extract<TaggedEnum.Kind<Z, A, B, C, D>, {
readonly _tag: Tag;
}>>): TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C, D>, Tag>
A, function (type parameter) B in <A, B, C, D>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B, C, D>, Tag, Extract<TaggedEnum.Kind<Z, A, B, C, D>, {
readonly _tag: Tag;
}>>): TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C, D>, Tag>
B, function (type parameter) C in <A, B, C, D>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B, C, D>, Tag, Extract<TaggedEnum.Kind<Z, A, B, C, D>, {
readonly _tag: Tag;
}>>): TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C, D>, Tag>
C, function (type parameter) D in <A, B, C, D>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B, C, D>, Tag, Extract<TaggedEnum.Kind<Z, A, B, C, D>, {
readonly _tag: Tag;
}>>): TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C, D>, Tag>
D>(
args: TaggedEnum.Args<
TaggedEnum.Kind<Z, A, B, C, D>,
Tag,
Extract<
TaggedEnum.Kind<Z, A, B, C, D>,
{
readonly _tag: Tag
}
>
>
args: TaggedEnum.type TaggedEnum<A extends Record<string, Record<string, any>> & UntaggedChildren<A>>.Args<A extends { readonly _tag: string; }, K extends A["_tag"], E = Extract<A, { readonly _tag: K; }>> = { readonly [K in keyof E as K extends "_tag" ? never : K]: E[K]; } extends infer T ? Types.VoidIfEmpty<T> : neverExtracts the constructor argument type for a specific variant of a tagged
union.
When to use
Use to derive the argument object expected by a constructor for one tagged
union variant.
Details
Returns void if the variant has no fields beyond _tag.
Example (Extracting variant args)
import type { Data } from "effect"
type Result =
| { readonly _tag: "Ok"; readonly value: number }
| { readonly _tag: "Err"; readonly error: string }
type OkArgs = Data.TaggedEnum.Args<Result, "Ok">
// { readonly value: number }
type ErrArgs = Data.TaggedEnum.Args<Result, "Err">
// { readonly error: string }
Args<
TaggedEnum.type TaggedEnum<A extends Record<string, Record<string, any>> & UntaggedChildren<A>>.Kind<Z extends TaggedEnum.WithGenerics<number>, A = unknown, B = unknown, C = unknown, D = unknown> = (Z & {
readonly A: A;
readonly B: B;
readonly C: C;
readonly D: D;
})["taggedEnum"]
Applies concrete type arguments to a WithGenerics definition, producing
the resulting tagged union type.
When to use
Use to refer to a specific instantiation of a generic tagged enum in type signatures.
Example (Applying generics)
import type { Data } from "effect"
type Option<A> = Data.TaggedEnum<{
None: {}
Some: { readonly value: A }
}>
interface OptionDef extends Data.TaggedEnum.WithGenerics<1> {
readonly taggedEnum: Option<this["A"]>
}
// Resolve to the concrete union for `string`
type StringOption = Data.TaggedEnum.Kind<OptionDef, string>
// { _tag: "None" } | { _tag: "Some"; value: string }
Kind<function (type parameter) Z in <Z extends TaggedEnum.WithGenerics<4>>(): Types.Simplify<{ readonly [Tag in Z["taggedEnum"]["_tag"]]: <A, B, C, D>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B, C, D>, Tag, Extract<TaggedEnum.Kind<Z, A, B, C, D>, {
readonly _tag: Tag;
}>>) => TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C, D>, Tag>; } & TaggedEnum.GenericMatchers<Z>>
Z, function (type parameter) A in <A, B, C, D>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B, C, D>, Tag, Extract<TaggedEnum.Kind<Z, A, B, C, D>, {
readonly _tag: Tag;
}>>): TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C, D>, Tag>
A, function (type parameter) B in <A, B, C, D>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B, C, D>, Tag, Extract<TaggedEnum.Kind<Z, A, B, C, D>, {
readonly _tag: Tag;
}>>): TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C, D>, Tag>
B, function (type parameter) C in <A, B, C, D>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B, C, D>, Tag, Extract<TaggedEnum.Kind<Z, A, B, C, D>, {
readonly _tag: Tag;
}>>): TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C, D>, Tag>
C, function (type parameter) D in <A, B, C, D>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B, C, D>, Tag, Extract<TaggedEnum.Kind<Z, A, B, C, D>, {
readonly _tag: Tag;
}>>): TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C, D>, Tag>
D>,
function (type parameter) TagTag,
type Extract<T, U> = T extends U
? T
: never
Extract from T those types that are assignable to U
Extract<TaggedEnum.type TaggedEnum<A extends Record<string, Record<string, any>> & UntaggedChildren<A>>.Kind<Z extends TaggedEnum.WithGenerics<number>, A = unknown, B = unknown, C = unknown, D = unknown> = (Z & {
readonly A: A;
readonly B: B;
readonly C: C;
readonly D: D;
})["taggedEnum"]
Applies concrete type arguments to a WithGenerics definition, producing
the resulting tagged union type.
When to use
Use to refer to a specific instantiation of a generic tagged enum in type signatures.
Example (Applying generics)
import type { Data } from "effect"
type Option<A> = Data.TaggedEnum<{
None: {}
Some: { readonly value: A }
}>
interface OptionDef extends Data.TaggedEnum.WithGenerics<1> {
readonly taggedEnum: Option<this["A"]>
}
// Resolve to the concrete union for `string`
type StringOption = Data.TaggedEnum.Kind<OptionDef, string>
// { _tag: "None" } | { _tag: "Some"; value: string }
Kind<function (type parameter) Z in <Z extends TaggedEnum.WithGenerics<4>>(): Types.Simplify<{ readonly [Tag in Z["taggedEnum"]["_tag"]]: <A, B, C, D>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B, C, D>, Tag, Extract<TaggedEnum.Kind<Z, A, B, C, D>, {
readonly _tag: Tag;
}>>) => TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C, D>, Tag>; } & TaggedEnum.GenericMatchers<Z>>
Z, function (type parameter) A in <A, B, C, D>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B, C, D>, Tag, Extract<TaggedEnum.Kind<Z, A, B, C, D>, {
readonly _tag: Tag;
}>>): TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C, D>, Tag>
A, function (type parameter) B in <A, B, C, D>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B, C, D>, Tag, Extract<TaggedEnum.Kind<Z, A, B, C, D>, {
readonly _tag: Tag;
}>>): TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C, D>, Tag>
B, function (type parameter) C in <A, B, C, D>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B, C, D>, Tag, Extract<TaggedEnum.Kind<Z, A, B, C, D>, {
readonly _tag: Tag;
}>>): TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C, D>, Tag>
C, function (type parameter) D in <A, B, C, D>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B, C, D>, Tag, Extract<TaggedEnum.Kind<Z, A, B, C, D>, {
readonly _tag: Tag;
}>>): TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C, D>, Tag>
D>, { readonly _tag: Tag extends Z["taggedEnum"]["_tag"]_tag: function (type parameter) TagTag }>
>
) => TaggedEnum.type TaggedEnum<A extends Record<string, Record<string, any>> & UntaggedChildren<A>>.Value<A extends { readonly _tag: string; }, K extends A["_tag"]> = A extends {
readonly _tag: K;
} ? A : never
Extracts the full variant type (including _tag) for a specific tag.
When to use
Use to select one full tagged-union variant by its _tag value.
Example (Extracting a variant type)
import type { Data } from "effect"
type Result =
| { readonly _tag: "Ok"; readonly value: number }
| { readonly _tag: "Err"; readonly error: string }
type OkVariant = Data.TaggedEnum.Value<Result, "Ok">
// { readonly _tag: "Ok"; readonly value: number }
Value<TaggedEnum.type TaggedEnum<A extends Record<string, Record<string, any>> & UntaggedChildren<A>>.Kind<Z extends TaggedEnum.WithGenerics<number>, A = unknown, B = unknown, C = unknown, D = unknown> = (Z & {
readonly A: A;
readonly B: B;
readonly C: C;
readonly D: D;
})["taggedEnum"]
Applies concrete type arguments to a WithGenerics definition, producing
the resulting tagged union type.
When to use
Use to refer to a specific instantiation of a generic tagged enum in type signatures.
Example (Applying generics)
import type { Data } from "effect"
type Option<A> = Data.TaggedEnum<{
None: {}
Some: { readonly value: A }
}>
interface OptionDef extends Data.TaggedEnum.WithGenerics<1> {
readonly taggedEnum: Option<this["A"]>
}
// Resolve to the concrete union for `string`
type StringOption = Data.TaggedEnum.Kind<OptionDef, string>
// { _tag: "None" } | { _tag: "Some"; value: string }
Kind<function (type parameter) Z in <Z extends TaggedEnum.WithGenerics<4>>(): Types.Simplify<{ readonly [Tag in Z["taggedEnum"]["_tag"]]: <A, B, C, D>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B, C, D>, Tag, Extract<TaggedEnum.Kind<Z, A, B, C, D>, {
readonly _tag: Tag;
}>>) => TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C, D>, Tag>; } & TaggedEnum.GenericMatchers<Z>>
Z, function (type parameter) A in <A, B, C, D>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B, C, D>, Tag, Extract<TaggedEnum.Kind<Z, A, B, C, D>, {
readonly _tag: Tag;
}>>): TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C, D>, Tag>
A, function (type parameter) B in <A, B, C, D>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B, C, D>, Tag, Extract<TaggedEnum.Kind<Z, A, B, C, D>, {
readonly _tag: Tag;
}>>): TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C, D>, Tag>
B, function (type parameter) C in <A, B, C, D>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B, C, D>, Tag, Extract<TaggedEnum.Kind<Z, A, B, C, D>, {
readonly _tag: Tag;
}>>): TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C, D>, Tag>
C, function (type parameter) D in <A, B, C, D>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B, C, D>, Tag, Extract<TaggedEnum.Kind<Z, A, B, C, D>, {
readonly _tag: Tag;
}>>): TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C, D>, Tag>
D>, function (type parameter) TagTag>
} & TaggedEnum.interface TaggedEnum<A extends Record<string, Record<string, any>> & UntaggedChildren<A>>.GenericMatchers<Z extends TaggedEnum.WithGenerics<number>>Type-guard and pattern-matching interface for generic tagged enums.
When to use
Use to type the $is and $match helpers for generic tagged enums.
Details
This is the $is / $match portion of the object returned by
taggedEnum
when used with a
WithGenerics
definition.
GenericMatchers<function (type parameter) Z in <Z extends TaggedEnum.WithGenerics<4>>(): Types.Simplify<{ readonly [Tag in Z["taggedEnum"]["_tag"]]: <A, B, C, D>(args: TaggedEnum.Args<TaggedEnum.Kind<Z, A, B, C, D>, Tag, Extract<TaggedEnum.Kind<Z, A, B, C, D>, {
readonly _tag: Tag;
}>>) => TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C, D>, Tag>; } & TaggedEnum.GenericMatchers<Z>>
Z>
>
<function (type parameter) A in <A extends {
readonly _tag: string;
}>(): TaggedEnum.Constructor<A>
A extends { readonly _tag: string_tag: string }>(): TaggedEnum.type TaggedEnum<A extends Record<string, Record<string, any>> & UntaggedChildren<A>>.Constructor<A extends { readonly _tag: string; }> = { [K in keyof ({ readonly [Tag in A["_tag"]]: TaggedEnum.ConstructorFrom<Extract<A, {
readonly _tag: Tag;
}>, "_tag">; } & {
readonly $is: <Tag extends A["_tag"]>(tag: Tag) => (u: unknown) => u is Extract<A, {
readonly _tag: Tag;
}>;
readonly $match: {
<Cases extends { readonly [Tag in A["_tag"]]: (args: Extract<A, {
readonly _tag: Tag;
}>) => any; }>(cases: Cases): (value: A) => Unify<ReturnType<Cases[A["_tag"]]>>;
<Cases extends { readonly [Tag in A["_tag"]]: (args: Extract<A, {
readonly _tag: Tag;
}>) => any; }>(value: A, cases: Cases): Unify<ReturnType<Cases[A["_tag"]]>>;
};
})]: ({ readonly [Tag in A["_tag"]]: TaggedEnum.ConstructorFrom<Extract<A, {
readonly _tag: Tag;
}>, "_tag">; } & {
readonly $is: <Tag extends A["_tag"]>(tag: Tag) => (u: unknown) => u is Extract<A, {
readonly _tag: Tag;
}>;
readonly $match: {
<Cases extends { readonly [Tag in A["_tag"]]: (args: Extract<A, {
readonly _tag: Tag;
}>) => any; }>(cases: Cases): (value: A) => Unify<ReturnType<Cases[A["_tag"]]>>;
<Cases extends { readonly [Tag in A["_tag"]]: (args: Extract<A, {
readonly _tag: Tag;
}>) => any; }>(value: A, cases: Cases): Unify<ReturnType<Cases[A["_tag"]]>>;
};
})[K]; } extends infer B ? B : never
The full constructors-and-matchers object type returned by
taggedEnum
.
When to use
Use when you want to annotate an exported constructor bundle so downstream
code keeps exact variant constructors and exhaustive matching.
Details
Includes:
- A constructor function for each variant (keyed by tag name)
$is(tag) — returns a type-guard that checks only the _tag field;
safe when the tag is globally unique and the value was produced by your
constructors. For untrusted input, validate with the Schema module first.
$match — exhaustive pattern matching (data-last or data-first)
Example (Using the constructor object)
import { Data } from "effect"
type Shape =
| { readonly _tag: "Circle"; readonly radius: number }
| { readonly _tag: "Rect"; readonly w: number; readonly h: number }
const { Circle, Rect, $is, $match } = Data.taggedEnum<Shape>()
const shape = Circle({ radius: 10 })
// Type guard
if ($is("Circle")(shape)) {
console.log(shape.radius)
}
// Pattern matching
const label = $match(shape, {
Circle: (s) => `circle r=${s.radius}`,
Rect: (s) => `rect ${s.w}x${s.h}`
})
Constructor<function (type parameter) A in <A extends {
readonly _tag: string;
}>(): TaggedEnum.Constructor<A>
A>
} = () =>
new var Proxy: ProxyConstructor
new <{}>(target: {}, handler: ProxyHandler<{}>) => {}
Creates a Proxy object. The Proxy object allows you to create an object that can be used in place of the
original object, but which may redefine fundamental Object operations like getting, setting, and defining
properties. Proxy objects are commonly used to log property accesses, validate, format, or sanitize inputs.
Proxy(
{},
{
ProxyHandler<{}>.get?(target: {}, p: string | symbol, receiver: any): anyA trap for getting a property value.
get(_target: {}_target, tag: string | symboltag, _receiver: any_receiver) {
if (tag: string | symboltag === "$is") {
return import PredicatePredicate.const isTagged: {
<K extends string>(tag: K): (
self: unknown
) => self is {
_tag: K
}
<K extends string>(
self: unknown,
tag: K
): self is {
_tag: K
}
}
Checks whether a value has a _tag property equal to the given tag.
When to use
Use when you model tagged unions with a _tag field and want a quick
Predicate guard for tagged values.
Details
Uses hasProperty and strict equality on _tag.
Example (Guarding tagged values)
import { Predicate } from "effect"
const isOk = Predicate.isTagged("Ok")
console.log(isOk({ _tag: "Ok", value: 1 }))
isTagged
} else if (tag: string | symboltag === "$match") {
return function taggedMatch<A extends {
readonly _tag: string;
}, Cases extends { readonly [K in A["_tag"]]: (args: Extract<A, {
readonly _tag: K;
}>) => any; }>(self: A, cases: Cases): ReturnType<Cases[A["_tag"]]> (+1 overload)
taggedMatch
}
return (props: anyprops: any) => ({ ...props: anyprops, _tag: string | symbol_tag: tag: string | symboltag })
}
}
) as any