effect-io-ai

Package: effect
Module: Types

Types.OmitReason

Narrows an error’s reason field to exclude a specific reason variant by its _tag.

When to use

Use to narrow the error to only the remaining reason variants after excluding the matched one.

Details

Returns never if E has no reason field or no remaining variants.

Example (Omitting 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.OmitReason<ApiError, "RateLimitError">
// ApiError & { readonly reason: { readonly _tag: "QuotaError"; readonly limit: number } }

See

Signature

type OmitReason<E, K> = E extends { readonly reason: infer R }
  ? R extends { readonly _tag: infer T } ? K extends T ? never : E & { readonly reason: R }
  : never
  : never

Source

Since v4.0.0