TagsWithReason<E>Type helper that keeps only error tags whose tagged error contains a tagged reason field.
When to use
Use to constrain custom helpers or overloads to parent error tags whose error contains a tagged reason.
Details
The mapped type keeps each parent error tag whose extracted tagged error has at least one reason tag, and removes tags that do not carry tagged reasons.
export type type TagsWithReason<E> = {
[T in Tags<E>]: ReasonTags<
ExtractTag<E, T>
> extends never
? never
: T
}[Tags<E>]
Type helper that keeps only error tags whose tagged error contains a tagged reason field.
When to use
Use to constrain custom helpers or overloads to parent error tags whose error
contains a tagged reason.
Details
The mapped type keeps each parent error tag whose extracted tagged error has
at least one reason tag, and removes tags that do not carry tagged reasons.
TagsWithReason<function (type parameter) E in type TagsWithReason<E>E> = {
[function (type parameter) TT in type Tags<E> = E extends {
readonly _tag: string;
} ? E["_tag"] : never
Extracts the _tag string literal types from a union.
When to use
Use to get all discriminant values from a tagged union type.
Details
Members without a _tag field are ignored and produce never.
Example (Extracting tags)
import type { Types } from "effect"
type MyError =
| { readonly _tag: "NotFound"; readonly id: string }
| { readonly _tag: "Timeout"; readonly ms: number }
| string
type Result = Types.Tags<MyError>
// "NotFound" | "Timeout"
Tags<function (type parameter) E in type TagsWithReason<E>E>]: type ReasonTags<E> = E extends {
readonly reason: {
readonly _tag: string;
};
} ? E["reason"]["_tag"] : never
Extracts the _tag values from the reason type of an error.
When to use
Use to get the discriminant values available inside a nested reason
error union.
Details
This is shorthand for Tags<ReasonOf<E>>. It returns never if E has no
reason field or the reason has no _tag.
Example (Getting reason tags)
import type { Types } from "effect"
type RateLimitError = { readonly _tag: "RateLimitError"; readonly retryAfter: number }
type QuotaError = { readonly _tag: "QuotaError"; readonly limit: number }
type ApiError = { readonly _tag: "ApiError"; readonly reason: RateLimitError | QuotaError }
type Result = Types.ReasonTags<ApiError>
// "RateLimitError" | "QuotaError"
ReasonTags<type ExtractTag<E, K extends string> = E extends {
readonly _tag: infer T;
} ? K extends T ? E : never : never
Extracts a specific member of a tagged union by its _tag value.
When to use
Use to select tagged-union members whose _tag matches a specific value in
type-level code.
Details
Returns never if no member matches the tag.
Example (Extracting a variant)
import type { Types } from "effect"
type MyError =
| { readonly _tag: "NotFound"; readonly id: string }
| { readonly _tag: "Timeout"; readonly ms: number }
type TimeoutError = Types.ExtractTag<MyError, "Timeout">
// { readonly _tag: "Timeout"; readonly ms: number }
ExtractTag<function (type parameter) E in type TagsWithReason<E>E, function (type parameter) TT>> extends never ? never : function (type parameter) TT
}[type Tags<E> = E extends {
readonly _tag: string;
} ? E["_tag"] : never
Extracts the _tag string literal types from a union.
When to use
Use to get all discriminant values from a tagged union type.
Details
Members without a _tag field are ignored and produce never.
Example (Extracting tags)
import type { Types } from "effect"
type MyError =
| { readonly _tag: "NotFound"; readonly id: string }
| { readonly _tag: "Timeout"; readonly ms: number }
| string
type Result = Types.Tags<MyError>
// "NotFound" | "Timeout"
Tags<function (type parameter) E in type TagsWithReason<E>E>]