Effect-TS: Handle Errors and Dependencies With Full Type Safety in TypeScript
Effect-TS tracks errors and dependencies in the type system - no more unknown catch blocks, no more implicit dependencies - here is how to adopt it in a real TypeScript project.
TypeScript has excellent type checking for the happy path. But try/catch gives you an unknown error type - the failure path is completely untyped. And dependencies (database clients, HTTP clients, config) are typically passed through function arguments or grabbed from globals - invisible to the type system.
Effect-TS solves both. Every Effect has three type parameters: Effect<Success, Error, Requirements>. The compiler tracks what can go wrong and what is needed to run.
The Effect Type
import { Effect } from "effect";
// Effect<User, UserNotFound | DatabaseError, DatabaseClient>
// Success: User
// Error: UserNotFound | DatabaseError
// Requirements: DatabaseClient
function getUser(id: string): Effect.Effect<User, UserNotFound | DatabaseError, DatabaseClient> {
return Effect.gen(function* () {
const db = yield* DatabaseClient;
const user = yield* db.findUser(id);
if (!user) yield* Effect.fail(new UserNotFound({ id }));
return user;
});
}
Team workspace
Ship faster with chat, meetings, and projects in one place — Zlyqor.
Practical deep-dives on LLMs, developer tools, and AI engineering. No filler. Unsubscribe any time.
// written byFIG. AUTH-01
530
Mahmudul Haque Qudrati
CEO & ML Engineer
CEO and ML Engineer at Pristren. Builds AI-powered software for teams and writes about machine learning, LLMs, developer tools, and practical AI applications.