Effect for TypeScript
Inspect the owning package and existing implementation first. Reuse established
project types, helpers, errors, lifecycle behavior, and test utilities. The
patterns below are options, not an implementation checklist. Introduce one only
when the current task requires it. Adopting Effect is not a mandate to maximize
Effect usage.
Project-specific rules
- Keep pure, total transformations synchronous.
- Add a
Context.Service only for a real injected dependency. Add a Layer only
when constructing that dependency or managing a resource lifetime.
- Add a tagged error only when callers handle it differently through HTTP mapping,
retry, cleanup, or orchestration.
- Reuse existing IDs, errors, validation, database services, and runtime.
- Preserve and reuse entity codecs; do not surround them with duplicate validation.
- Treat existing code as evidence of project conventions, not automatic permission
to copy its ceremony.
- Keep Effect execution explicit at the application boundary.
- A domain model may construct an Effect value for typed success, failure, or
absence. Construction is not I/O; keep the value free of external requirements
and do not run it in the domain model.
- Keep Layers, runtimes, configuration, environment access, database clients,
and other I/O dependencies outside domain models.
- Use native resource finalizers; do not surround sufficient library cleanup with
custom lifecycle machinery.
Effect v3 and v4 share the same programming model but differ in important API names and shapes. Resolve the project's version before writing or reviewing code.
Resolve the version first
- Read the nearest
package.json that owns the target source file.
- Inspect its
effect dependency and any @effect/* packages. Use the lockfile when a workspace range, alias, prerelease tag, or indirect dependency makes the resolved major unclear.
- In a monorepo, resolve the version separately for each package. Do not assume the root version applies everywhere.
- Route major version 3 to
references/v3/ and major version 4 or later to references/v4/.
- If no version can be discovered and the user did not name one, ask which major to target.
The installed package and its declarations are authoritative. This matters especially for prereleases, whose APIs can change between releases.
Load only the relevant references
After resolving the major, read the matching topic guide:
| Topic |
Effect v3 |
Effect v4+ |
| Core effects, generators, fibers, concurrency |
v3 core |
v4 core |
| Typed errors, recovery, retry, timeout |
v3 errors |
v4 errors |
| Services, dependency injection, layers |
v3 services |
v4 services |
| Schema, decoding, encoding, validation |
v3 Schema |
v4 Schema |
| Scope and resource safety |
v3 resources |
v4 resources |
| Drizzle ORM with Effect PostgreSQL |
Verify the installed driver supports v3 |
v4 Drizzle PostgreSQL |
For an upgrade from v3 to v4, first read the migration guide, then load the affected v4 topic guides.
Shared principles
- Keep
Effect<A, E, R> lazy and run it only at application boundaries.
- Model expected failures in
E; reserve defects for broken invariants and unrecoverable faults.
- Validate untrusted data at system boundaries with Schema.
- Express real dependencies as services and use Layers when construction or resource
lifetime requires them.
- Scope every resource whose acquisition has a release action.
- Use structured concurrency and explicit concurrency limits.
- Prefer
Effect.gen for sequential workflows and pipe for focused transformations.
Version guardrails
- Do not copy a symbol from the other version because its name looks familiar.
- Do not upgrade package versions unless the user asked for a migration.
- On v4, check that all Effect ecosystem packages use the same release version.
- Treat
effect/unstable/* as allowed to break in minor releases; verify its API against the installed package.
- When examples and installed declarations disagree, follow the declarations and explain the version-specific difference.
1---2name: typescript-effect-ts3description: Build, review, or migrate TypeScript applications using Effect v3 or v4. Use whenever code imports from effect or @effect/*, integrates drizzle-orm/effect-postgres with @effect/sql-pg, or works with Effect.gen, typed errors, Result or Either, Context services, Layer dependency injection, Schema validation, fibers, concurrency, Scope, or acquireRelease. Resolve the installed Effect major before suggesting APIs so v3 and v4 syntax are never mixed.4---56# Effect for TypeScript78Inspect the owning package and existing implementation first. Reuse established9project types, helpers, errors, lifecycle behavior, and test utilities. The10patterns below are options, not an implementation checklist. Introduce one only11when the current task requires it. Adopting Effect is not a mandate to maximize12Effect usage.1314## Project-specific rules1516- Keep pure, total transformations synchronous.17- Add a `Context.Service` only for a real injected dependency. Add a `Layer` only18 when constructing that dependency or managing a resource lifetime.19- Add a tagged error only when callers handle it differently through HTTP mapping,20 retry, cleanup, or orchestration.21- Reuse existing IDs, errors, validation, database services, and runtime.22- Preserve and reuse entity codecs; do not surround them with duplicate validation.23- Treat existing code as evidence of project conventions, not automatic permission24 to copy its ceremony.25- Keep Effect execution explicit at the application boundary.26- A domain model may construct an Effect value for typed success, failure, or27 absence. Construction is not I/O; keep the value free of external requirements28 and do not run it in the domain model.29- Keep Layers, runtimes, configuration, environment access, database clients,30 and other I/O dependencies outside domain models.31- Use native resource finalizers; do not surround sufficient library cleanup with32 custom lifecycle machinery.3334Effect v3 and v4 share the same programming model but differ in important API names and shapes. Resolve the project's version before writing or reviewing code.3536## Resolve the version first37381. Read the nearest `package.json` that owns the target source file.392. Inspect its `effect` dependency and any `@effect/*` packages. Use the lockfile when a workspace range, alias, prerelease tag, or indirect dependency makes the resolved major unclear.403. In a monorepo, resolve the version separately for each package. Do not assume the root version applies everywhere.414. Route major version 3 to `references/v3/` and major version 4 or later to `references/v4/`.425. If no version can be discovered and the user did not name one, ask which major to target.4344The installed package and its declarations are authoritative. This matters especially for prereleases, whose APIs can change between releases.4546## Load only the relevant references4748After resolving the major, read the matching topic guide:4950| Topic | Effect v3 | Effect v4+ |51| --- | --- | --- |52| Core effects, generators, fibers, concurrency | [v3 core](./references/v3/core.md) | [v4 core](./references/v4/core.md) |53| Typed errors, recovery, retry, timeout | [v3 errors](./references/v3/error-handling.md) | [v4 errors](./references/v4/error-handling.md) |54| Services, dependency injection, layers | [v3 services](./references/v3/services.md) | [v4 services](./references/v4/services.md) |55| Schema, decoding, encoding, validation | [v3 Schema](./references/v3/schema.md) | [v4 Schema](./references/v4/schema.md) |56| Scope and resource safety | [v3 resources](./references/v3/resources.md) | [v4 resources](./references/v4/resources.md) |57| Drizzle ORM with Effect PostgreSQL | Verify the installed driver supports v3 | [v4 Drizzle PostgreSQL](./references/v4/drizzle-effect-postgres.md) |5859For an upgrade from v3 to v4, first read [the migration guide](./references/v3-to-v4.md), then load the affected v4 topic guides.6061## Shared principles6263- Keep `Effect<A, E, R>` lazy and run it only at application boundaries.64- Model expected failures in `E`; reserve defects for broken invariants and unrecoverable faults.65- Validate untrusted data at system boundaries with Schema.66- Express real dependencies as services and use Layers when construction or resource67 lifetime requires them.68- Scope every resource whose acquisition has a release action.69- Use structured concurrency and explicit concurrency limits.70- Prefer `Effect.gen` for sequential workflows and `pipe` for focused transformations.7172## Version guardrails7374- Do not copy a symbol from the other version because its name looks familiar.75- Do not upgrade package versions unless the user asked for a migration.76- On v4, check that all Effect ecosystem packages use the same release version.77- Treat `effect/unstable/*` as allowed to break in minor releases; verify its API against the installed package.78- When examples and installed declarations disagree, follow the declarations and explain the version-specific difference.