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 | QuotaErrorSource effect/Types.ts:9221 lines
export type type ReasonOf<E> = E extends {
readonly reason: infer R
}
? R
: never
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
ReasonOf<function (type parameter) E in type ReasonOf<E>E> = function (type parameter) E in type ReasonOf<E>E extends { readonly reason: Rreason: infer function (type parameter) RR } ? function (type parameter) RR : neverReferenced by 2 symbols