DEV Community

Alex Spinov
Alex Spinov

Posted on

Effect-TS Has a Free API You Should Know About

Effect-TS is a comprehensive TypeScript library for building production-grade applications. It provides typed errors, dependency injection, concurrency, and observability — all with full type safety.

Why Effect-TS for Serious TypeScript

A backend team had try-catch blocks everywhere, inconsistent error handling, and no way to know what errors a function could throw. Effect-TS makes errors part of the type signature — the compiler tells you exactly what can go wrong.

Key Features:

  • Typed Errors — Errors are part of the type signature
  • Dependency Injection — Compile-time verified DI
  • Concurrency — Structured concurrency with fibers
  • Retry & Timeout — Built-in resilience patterns
  • Observability — Tracing, metrics, logging built-in

Quick Start

npm install effect
Enter fullscreen mode Exit fullscreen mode
import { Effect } from "effect"

const divide = (a: number, b: number): Effect.Effect<number, Error> =>
  b === 0
    ? Effect.fail(new Error("Division by zero"))
    : Effect.succeed(a / b)

const program = divide(10, 2).pipe(
  Effect.map(result => `Result: ${result}`),
  Effect.catchAll(error => Effect.succeed(`Error: ${error.message}`))
)

Effect.runPromise(program).then(console.log) // "Result: 5"
Enter fullscreen mode Exit fullscreen mode

Service Layer

import { Context, Effect, Layer } from "effect"

class Database extends Context.Tag("Database")<Database, {
  query: (sql: string) => Effect.Effect<unknown[]>
}>() {}

const program = Database.pipe(
  Effect.flatMap(db => db.query("SELECT * FROM users"))
)

const DatabaseLive = Layer.succeed(Database, {
  query: (sql) => Effect.succeed([{ id: 1, name: "Alice" }])
})

Effect.runPromise(Effect.provide(program, DatabaseLive))
Enter fullscreen mode Exit fullscreen mode

Why Choose Effect-TS

  1. Typed errors — know exactly what can fail
  2. Dependency injection — compile-time verified
  3. Production patterns — retry, timeout, circuit breaker built-in

Check out Effect docs to get started.


Building robust TypeScript? Check out my Apify actors or email spinov001@gmail.com for custom solutions.

Top comments (0)