0Pricing
TypeScript Academy · Lesson

The Effect Type

Understand Effect .

The Effect Type is a free TypeScript Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the TypeScript Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

The Effect Type

The central type is Effect<Success, Error, Requirements>. Its three type parameters describe everything a computation can do: what it produces, how it can fail, and what it needs.

import { Effect } from "effect";
// Effect<A, E, R>
//   A = success value type
//   E = error type
//   R = required services (dependencies)

The Success Channel (A)

The first parameter is the value produced on success. Effect.succeed creates an effect that always yields a value with no errors and no requirements.

import { Effect } from "effect";

const ok = Effect.succeed(42);
// Effect<number, never, never>

The Error Channel (E)

The second parameter is the typed error. never means the effect cannot fail. A real error type means callers must account for it.

import { Effect } from "effect";

class NotFound { readonly _tag = "NotFound"; }
const failing = Effect.fail(new NotFound());
// Effect<never, NotFound, never>

The Requirements Channel (R)

The third parameter lists services the effect depends on. never means it is self-contained; otherwise it cannot run until those services are provided.

// Conceptually:
// Effect<User, NotFound, Database>
// produces a User, may fail with NotFound, needs a Database

Reading a Signature

You can read an effect type like a sentence: "produces A, or fails with E, given R". This single type replaces a Promise plus implicit throws plus hidden globals.

never as Identity

never is the neutral value for the E and R channels: no possible error, no required dependency. As you compose, error and requirement types accumulate as unions.

Creating Effects From Values

Common constructors: succeed (pure value), fail (typed error), and sync (wrap a synchronous side effect).

import { Effect } from "effect";

const now = Effect.sync(() => Date.now());
// Effect<number, never, never>

Wrapping Async Work

Effect.promise and Effect.tryPromise lift promises into effects; tryPromise lets you map rejection into a typed error in the E channel.

import { Effect } from "effect";

const fetchUser = Effect.tryPromise({
  try: () => fetch("/user").then((r) => r.json()),
  catch: (e) => new Error("fetch failed: " + String(e)),
});
// Effect<any, Error, never>

Type Aliases for Channels

For services, Effect provides Effect.Effect<A, E, R> as the full name. The channels are independent: you can have errors with no requirements, or requirements with no errors.

Why Three Channels

Three channels capture the three things that make code hard to reason about: the result, the failure modes, and the context it runs in. Surfacing all three in one type is what gives Effect its safety guarantees.

Why This Matters

Understanding Effect<A, E, R> is the key to everything else: composition combines these channels, error handling narrows E, and providing dependencies clears R. Read the type and you know exactly what a computation does.

Quick Check

Confirm your understanding of the Effect type.

Recap

Effect<A, E, R> encodes the success value, the typed error, and the required dependencies in one type. never is the neutral value for E and R. Constructors like succeed, fail, sync, and tryPromise build effects with the appropriate channels.

Frequently asked questions

Is the “The Effect Type” lesson free?

Yes — the full text of “The Effect Type” is free to read here on the web, and the TypeScript Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the TypeScript Academy course, upgrade to CoddyKit PRO.

What will I learn in “The Effect Type”?

Understand Effect . You practise TypeScript Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start TypeScript Academy?

No prior experience is required. TypeScript Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “The Effect Type” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this TypeScript Academy lesson?

Yes. Every TypeScript Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

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