The first Effect post gave me the shape:
Effect.Effect<Success, Error, Requirements>;Now I want the smallest thing I can build with it.
No services. No architecture. No big theory.
Just success and failure.
The plain version
In plain TypeScript, success and failure take different roads.
const getName = (input: string): string => { if (input === "") { throw new Error("Name is required"); }
return input;};Success comes back through return.
Failure leaves through throw.
Only one of them shows up in the type.
Effect gives both of them a value you can hold.
A successful Effect
import { Effect } from "effect";
const answer = Effect.succeed(42);The type is:
Effect.Effect<number, never, never>;Read it slowly:
- success:
number - error:
never - requirements:
never
This Effect gives you a number. It cannot fail. It needs nothing.
A failed Effect
class MissingName { readonly _tag = "MissingName";}
const failed = Effect.fail(new MissingName());The type is:
Effect.Effect<never, MissingName, never>;That looks weird at first.
But it makes sense. This Effect does not produce a success value. It only fails.
So the success slot is never.
The pipe is just the path
Effect code often uses .pipe(...).
const program = Effect.succeed("trillo").pipe( Effect.map((name) => name.toUpperCase()),);This reads as:
- start with
"trillo" - turn it into uppercase
- return a new Effect
The program still has not run.
It is still a description.
The mistake: throwing inside an Effect
Old habits come back fast.
const getName = (input: string) => Effect.sync(() => { if (input === "") { throw new MissingName(); }
return input; });This compiles.
The type is Effect.Effect<string, never, never>.
The error slot says never. The code can still fail.
Effect treats that throw as a defect. A defect is a crash you did not plan for. It never shows up in the error slot.
How to spot it: a throw inside Effect.sync, next to an error slot that says never.
Return the failure instead:
const getName = (input: string) => input === "" ? Effect.fail(new MissingName()) : Effect.succeed(input);Now the type is Effect.Effect<string, MissingName, never>.
The failure is back where you can see it.
What I am taking with me
succeed and fail are not magic.
They are just the two smallest Effect values:
Effect.succeed(value);Effect.fail(error);One fills the success slot.
One fills the error slot.

