Hyperlinkv0.8.0-beta.28

Types

Types.ExtractReasontypeeffect/Types.ts:992
ExtractReason<E, K>

Extracts a specific reason variant by its _tag from an error's reason field.

When to use

Use when you need the nested reason variant type itself, selected by _tag, rather than the enclosing error type.

Details

Returns never if E has no matching reason variant.

Example (Extracting a reason variant)

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.ExtractReason<ApiError, "RateLimitError">
// { readonly _tag: "RateLimitError"; readonly retryAfter: number }
Source effect/Types.ts:9924 lines
export type ExtractReason<E, K extends string> = E extends { readonly reason: infer R }
  ? R extends { readonly _tag: infer T } ? K extends T ? R : never
  : never
  : never
Referenced by 7 symbols