effect-io-ai

Package: effect
Module: Types

Types.ReasonOf

Extracts the reason type from an error that has a reason field.

When to use

Use when an error type stores nested sub-errors in a reason field and you need that field’s full union type as a standalone type.

Details

Returns never if E has no reason field.

Example (Extracting reason types)

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 Reasons = Types.ReasonOf<ApiError>
// RateLimitError | QuotaError

See

Signature

type ReasonOf<E> = E extends { readonly reason: infer R } ? R : never

Source

Since v4.0.0