0Pricing
TypeScript Academy · Lesson

Error Channels and Dependencies

Track typed errors and injected dependencies in effects.

Error Channels and Dependencies

Two channels make Effect powerful: the typed error channel (E) and the requirements channel (R). This lesson shows how to fail with typed errors and how to provide dependencies via Context and Layer.

Typed Failures With Effect.fail

Effect.fail places a value into the error channel. Tagged classes make errors easy to discriminate.

import { Effect } from "effect";

class NotFound { readonly _tag = "NotFound"; }
class Forbidden { readonly _tag = "Forbidden"; }

const load = Effect.fail(new NotFound());
// Effect<never, NotFound, never>

All lessons in this course

  1. Why Effect Systems Matter
  2. The Effect Type
  3. Composing Effects
  4. Error Channels and Dependencies
← Back to TypeScript Academy