Hyperlinkv0.8.0-beta.28

Types

Types.OmitReasontypeeffect/Types.ts:1069
OmitReason<E, K>

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 } }
Source effect/Types.ts:10694 lines
export type OmitReason<E, K extends string> = E extends { readonly reason: infer R }
  ? R extends { readonly _tag: infer T } ? K extends T ? never : E & { readonly reason: R }
  : never
  : never
Referenced by 6 symbols