Effect
Functional effect system for TypeScript unifying errors, retries, concurrency, and dependency injection.
Official Documentation ↗v3. Check the official docs for the latest API surface.Installation
npm install effectpnpm add effectMethods
No methods match this filter.
Functional effect system for TypeScript unifying errors, retries, concurrency, and dependency injection.
Overview
Effect models computations as values: an Effect carries success and error types plus requirements, composes through combinators, and runs only at the boundary. Generator syntax makes sequencing read like async/await while errors stay typed end to end.
On that foundation it builds retry and timeout policies, structured concurrency with interruption, and a service layer for testable dependency injection. The result is application logic whose failure modes and inputs are visible in the types themselves.
Core Methods
The most frequently used entry points, with signatures and runnable examples:
Effect.succeed / Effect.fail— Creates effect values describing a guaranteed success or failure without running anything.Effect.gen— Generator syntax for sequencing effects with typed error propagation through yield*.Effect.runPromise / runSync— Executes an effect at the boundary, converting the typed error into a rejected promise.Effect.timeout / retry— Adds failure-management policies declaratively, composing with the error channel types.Data.TaggedError— Defines discriminated error classes that keep the error channel fully typed and matchable.
Usage Notes
- Start at API boundaries: build one effect, run it in the handler, keep the rest unchanged.
- Model errors with Data.TaggedError so handlers can switch on the error type.
- Reserve runPromise for the outermost edge; inside programs stay composed.
Common Pitfalls
- Awaiting an effect directly does nothing, they are values, not promises; use runPromise.
- Deeply nested gen blocks obscure the flow, extract named effects per step.
- Jumping into Layers and services before mastering the core slows teams down.
Errors
The following points are quoted verbatim from the official documentation. 来源:https://effect.website/ · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:49:22.786Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.
- Start Scale Complexity at scale: Without Effect With Effect Try-catch blocks everywhere but you still do not know how things can fail. (https://effect.website/)
- “Effect makes doing the hard, tedious, and error-prone tasks that require discipline, easy, natural, first-class.” Dillon Mulroy “Effect tracing is simply magical. (https://effect.website/)
- Pick one problem everyone hates: Dependency injection… Error management… Concurrency… Let the quality of the code speak for itself. (https://effect.website/)
Security notes
Quoted verbatim from the official documentation; this is not a complete threat model. 来源:https://effect.website/ · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:49:22.786Z.
- Dependency Injection Type-safe service definitions Automatic dependency resolution Easy mocking for tests That Promise.all call? (https://effect.website/)
- Pick one problem everyone hates: Dependency injection… Error management… Concurrency… Let the quality of the code speak for itself. (https://effect.website/)
FAQ
- What is an effect exactly?
- An effect is a value describing a computation, including its error type and requirements, that runs only when executed with runPromise or runSync. That indirection lets the type system track failures and lets combinators like retry compose before anything executes.
- How is this different from promises with try/catch?
- Promises erase error types to unknown and offer no built-in retry, timeout, or interruption. Effects keep errors in the type, compose declaratively, and support structured concurrency and cancellation that promises cannot express.
- What is the learning curve like?
- The core, succeed, fail, gen, run, is approachable in a day. The deeper layers, services with Layers and dependency injection, schedulers, fibers, take longer. Teams usually adopt incrementally at API boundaries first.
Report a problem with this API docOpens a pre-filled issue on GitHub.