Installation
Install Effect using your preferred package manager:Effect requires TypeScript 5.4 or newer. Make sure to enable
strict mode in your tsconfig.json.Your First Effect Program
Effect programs are built using theEffect.gen function, which provides a generator-based syntax similar to async/await:
Create an Effect
Create a simple effect that performs a computation:The
Effect.succeed creates an effect that always succeeds with the given value. The yield* keyword unwraps the value from the effect.Run the Effect
Execute your effect using
Effect.runPromise:Effect.runPromise runs the effect and returns a Promise with the result.Add Error Handling
Effect makes error handling explicit and type-safe:The type signature
Effect<number, string, never> tells you:- Returns a
numberon success - Fails with a
stringerror - Requires no dependencies (
never)
Working with Promises
Effect makes it easy to work with existing Promise-based code:tryPromise function converts a Promise into an Effect, allowing you to specify how to handle rejection errors.
Error Recovery
Effect provides powerful error recovery operators:Next Steps
Now that you’ve written your first Effect program, explore these topics:Error Handling
Master type-safe error handling patterns
Concurrency
Learn about fibers and concurrent execution
Dependency Injection
Build modular applications with Context and Layer
Resource Management
Safely manage resources with automatic cleanup