Hyperlinkv0.8.0-beta.28

Types

Types.ReasonOftypeeffect/Types.ts:922
ReasonOf<E>

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
Source effect/Types.ts:9221 lines
export type ReasonOf<E> = E extends { readonly reason: infer R } ? R : never
Referenced by 2 symbols