<E>(): <A, E2 extends E, R>(effect: Effect<A, E2, R>) => Effect<A, E2, R>Ensures that an effect's error type extends a given type E.
Details
This helper is checked at compile time and does not change the effect's runtime behavior.
Example (Constraining the error type)
import { Data, Effect } from "effect"
class ValidationError extends Data.TaggedError("ValidationError")<{}> {}
// Define a constraint that the error type must be a ValidationError
const satisfiesError = Effect.satisfiesErrorType<ValidationError>()
// This works - Effect<number, ValidationError, never> extends the constrained type
const validEffect = satisfiesError(Effect.fail(new ValidationError()))
// This would cause a TypeScript compilation error:
// const invalidEffect = satisfiesError(Effect.fail("string error"))
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^
// Type 'string' is not assignable to type 'ValidationError'export const const satisfiesErrorType: <E>() => <
A,
E2 extends E,
R
>(
effect: Effect<A, E2, R>
) => Effect<A, E2, R>
Ensures that an effect's error type extends a given type E.
Details
This helper is checked at compile time and does not change the effect's
runtime behavior.
Example (Constraining the error type)
import { Data, Effect } from "effect"
class ValidationError extends Data.TaggedError("ValidationError")<{}> {}
// Define a constraint that the error type must be a ValidationError
const satisfiesError = Effect.satisfiesErrorType<ValidationError>()
// This works - Effect<number, ValidationError, never> extends the constrained type
const validEffect = satisfiesError(Effect.fail(new ValidationError()))
// This would cause a TypeScript compilation error:
// const invalidEffect = satisfiesError(Effect.fail("string error"))
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^
// Type 'string' is not assignable to type 'ValidationError'
satisfiesErrorType = <function (type parameter) E in <E>(): <A, E2 extends E, R>(effect: Effect<A, E2, R>) => Effect<A, E2, R>E>() => <function (type parameter) A in <A, E2 extends E, R>(effect: Effect<A, E2, R>): Effect<A, E2, R>A, function (type parameter) E2 in <A, E2 extends E, R>(effect: Effect<A, E2, R>): Effect<A, E2, R>E2 extends function (type parameter) E in <E>(): <A, E2 extends E, R>(effect: Effect<A, E2, R>) => Effect<A, E2, R>E, function (type parameter) R in <A, E2 extends E, R>(effect: Effect<A, E2, R>): Effect<A, E2, R>R>(effect: Effect<A, E2, R>(parameter) effect: {
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
effect: interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<function (type parameter) A in <A, E2 extends E, R>(effect: Effect<A, E2, R>): Effect<A, E2, R>A, function (type parameter) E2 in <A, E2 extends E, R>(effect: Effect<A, E2, R>): Effect<A, E2, R>E2, function (type parameter) R in <A, E2 extends E, R>(effect: Effect<A, E2, R>): Effect<A, E2, R>R>): interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<function (type parameter) A in <A, E2 extends E, R>(effect: Effect<A, E2, R>): Effect<A, E2, R>A, function (type parameter) E2 in <A, E2 extends E, R>(effect: Effect<A, E2, R>): Effect<A, E2, R>E2, function (type parameter) R in <A, E2 extends E, R>(effect: Effect<A, E2, R>): Effect<A, E2, R>R> => effect: Effect<A, E2, R>(parameter) effect: {
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
effect