Effect-TS is a robust, type-safe functional programming library for TypeScript, providing a "missing standard library" for building highly concurrent, resilient, and performant applications. It centers around the `Effect` data type, which represents a description of a computation that may require resources (R), may fail with an error (E), and may succeed with a value (A). The library promotes a functional-first approach, emphasizing immutability, explicit error handling, and structured concurrency, leveraging TypeScript's type system to ensure correctness at compile-time. Currently stable at version 3.x (e.g., 3.21.1), `effect` maintains a regular release cadence with frequent patch and minor updates, reflecting active development and continuous improvement. It differentiates itself through its comprehensive ecosystem of modules (e.g., `Effect.Layer`, `Effect.Schema`, `Effect.Stream`) that integrate seamlessly, offering a complete solution for complex application logic, asynchronous operations, and resource management without runtime exceptions.
npm install effectVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates creating and composing Effects, handling different types of errors with custom error classes, using `pipe` for composition, applying retry logic, and running the Effect to a Promise, including a simulated database defect.
Consult the official migration guide for the specific major version upgrade. For v3, update imports, service definitions, Effect.gen usage, and error types.
Always ensure your Effect computation is eventually passed to a runner function, typically at the 'edge' of your application or within a specific execution context.
Familiarize yourself with Effect's dependency injection system (Services and Layers). Ensure all required dependencies are correctly provided to your Effect computations via `Effect.provide` or `Layer.provide`.
Always use `yield*` when composing Effect values inside an `Effect.gen` block. `yield*` performs the unwrapping and error propagation within the Effect runtime.
Update to `effect@3.21.1` or later to include the fix that ensures request `Deferred`s are completed even if the resolver dies with a defect.
Ensure you are calling `Effect.runPromise` on an actual `Effect` instance, e.g., `Effect.runPromise(myEffect)`. Also, check your imports for `Effect` to ensure it's not a `require` import if your project is ESM-first.
Explicitly specify the type parameters (`Effect<A, E, R>`) for effects, especially when defining functions that return them. Use `Effect.mapError`, `Effect.provide`, `Effect.catchAll` to adjust error and requirement types. When composing, ensure the types align or are handled.
Convert Promises to Effects using `Effect.promise`, `Effect.tryPromise`, or `Effect.async` (for more complex async operations). Do not `await` Effect values directly; use `yield*` within `Effect.gen`.
Ensure methods are called correctly. If using the fluent `.pipe()` syntax, ensure it's on an Effect instance (`myEffect.pipe(Effect.map(...))`). If using the global `pipe` function, ensure it takes the value as its first argument (`pipe(myEffect, Effect.map(...))`).
No dependency data recorded yet.