new <A extends Record<string, any> = {}>(
args: Types.VoidIfEmpty<{ readonly [P in keyof A]: A[P] }>
) => Cause.YieldableError & Readonly<A>Provides a base class for yieldable errors.
When to use
Use when you need yieldable errors that do not need tag-based discrimination.
Details
Extends Cause.YieldableError, so instances can be yielded inside
Effect.gen to fail the enclosing effect. Fields are passed as a single
object; when there are no fields the argument is optional. If a message
field is provided, it becomes the error's .message.
Example (Defining a yieldable error)
import { Data, Effect } from "effect"
class NetworkError extends Data.Error<{
readonly code: number
readonly message: string
}> {}
const program = Effect.gen(function*() {
return yield* new NetworkError({ code: 500, message: "timeout" })
})
// The effect fails with a NetworkError
Effect.runSync(Effect.exit(program))export const const Error: new <
A extends Record<string, any> = {}
>(
args: Types.VoidIfEmpty<{
readonly [P in keyof A]: A[P]
}>
) => Cause.YieldableError & Readonly<A>
Provides a base class for yieldable errors.
When to use
Use when you need yieldable errors that do not need tag-based
discrimination.
Details
Extends Cause.YieldableError, so instances can be yielded inside
Effect.gen to fail the enclosing effect. Fields are passed as a single
object; when there are no fields the argument is optional. If a message
field is provided, it becomes the error's .message.
Example (Defining a yieldable error)
import { Data, Effect } from "effect"
class NetworkError extends Data.Error<{
readonly code: number
readonly message: string
}> {}
const program = Effect.gen(function*() {
return yield* new NetworkError({ code: 500, message: "timeout" })
})
// The effect fails with a NetworkError
Effect.runSync(Effect.exit(program))
Error: new<function (type parameter) A in <A extends Record<string, any> = {}>(args: Types.VoidIfEmpty<{ readonly [P in keyof A]: A[P]; }>): Cause.YieldableError & Readonly<A>A extends type Record<K extends keyof any, T> = {
[P in K]: T
}
Construct a type with a set of properties K of type T
Record<string, any> = {}>(
args: Types.VoidIfEmpty<{
readonly [P in keyof A]: A[P]
}>
args: import TypesTypes.type VoidIfEmpty<S> =
keyof S extends never ? void : S
Conditional type that returns void if S is an empty object type,
otherwise returns S.
When to use
Use to erase an empty object type from an API result or parameter position.
VoidIfEmpty<{ readonly [function (type parameter) PP in keyof function (type parameter) A in <A extends Record<string, any> = {}>(args: Types.VoidIfEmpty<{ readonly [P in keyof A]: A[P]; }>): Cause.YieldableError & Readonly<A>A]: function (type parameter) A in <A extends Record<string, any> = {}>(args: Types.VoidIfEmpty<{ readonly [P in keyof A]: A[P]; }>): Cause.YieldableError & Readonly<A>A[function (type parameter) PP] }>
) => import CauseCause.type Cause.YieldableError = /*unresolved*/ anyYieldableError & type Readonly<T> = {
readonly [P in keyof T]: T[P]
}
Make all properties in T readonly
Readonly<function (type parameter) A in <A extends Record<string, any> = {}>(args: Types.VoidIfEmpty<{ readonly [P in keyof A]: A[P]; }>): Cause.YieldableError & Readonly<A>A> = import corecore.const Error: new <
A extends Record<string, any> = {}
>(
args: Types.VoidIfEmpty<{
readonly [P in keyof A]: A[P]
}>
) => Cause.YieldableError & Readonly<A>
Error