NarrowReason<E, K>Narrows a specific reason variant by its _tag from an error's reason
field.
When to use
Use to preserve the original error shape while narrowing its nested reason field to the matching variant.
Details
Returns never if E has no matching reason variant.
Example (Narrowing 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.NarrowReason<ApiError, "RateLimitError">
// ApiError & { readonly reason: { readonly _tag: "RateLimitError"; readonly retryAfter: number } }Source effect/Types.ts:10304 lines
export type type NarrowReason<
E,
K extends string
> = E extends {
readonly reason: infer R
}
? R extends {
readonly _tag: infer T
}
? K extends T
? E & {
readonly reason: R
}
: never
: never
: never
Narrows a specific reason variant by its _tag from an error's reason
field.
When to use
Use to preserve the original error shape while narrowing its nested reason
field to the matching variant.
Details
Returns never if E has no matching reason variant.
Example (Narrowing 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.NarrowReason<ApiError, "RateLimitError">
// ApiError & { readonly reason: { readonly _tag: "RateLimitError"; readonly retryAfter: number } }
NarrowReason<function (type parameter) E in type NarrowReason<E, K extends string>E, function (type parameter) K in type NarrowReason<E, K extends string>K extends string> = function (type parameter) E in type NarrowReason<E, K extends string>E extends { readonly reason: Rreason: infer function (type parameter) RR }
? function (type parameter) RR extends { readonly _tag: T_tag: infer function (type parameter) TT } ? function (type parameter) K in type NarrowReason<E, K extends string>K extends function (type parameter) TT ? function (type parameter) E in type NarrowReason<E, K extends string>E & { readonly reason: Rreason: function (type parameter) RR } : never
: never
: neverReferenced by 6 symbols