Skip to main content
This quickstart will get you up and running with Effect in minutes. You’ll install the library, write your first Effect program, and learn the basics of running effects.

Installation

Install Effect using your preferred package manager:
npm install effect
Effect requires TypeScript 5.4 or newer. Make sure to enable strict mode in your tsconfig.json.

Your First Effect Program

Effect programs are built using the Effect.gen function, which provides a generator-based syntax similar to async/await:
1

Create an Effect

Create a simple effect that performs a computation:
import { Effect } from "effect"

const hello = Effect.gen(function* () {
  const message = yield* Effect.succeed("Hello, Effect!")
  return message.toUpperCase()
})
The Effect.succeed creates an effect that always succeeds with the given value. The yield* keyword unwraps the value from the effect.
2

Run the Effect

Execute your effect using Effect.runPromise:
Effect.runPromise(hello).then(console.log)
// Output: HELLO, EFFECT!
Effect.runPromise runs the effect and returns a Promise with the result.
3

Add Error Handling

Effect makes error handling explicit and type-safe:
import { Effect } from "effect"

const divide = (a: number, b: number) =>
  Effect.gen(function* () {
    if (b === 0) {
      return yield* Effect.fail("Division by zero")
    }
    return a / b
  })

// Success case
Effect.runPromise(divide(10, 2)).then(console.log)
// Output: 5

// Error case
Effect.runPromise(divide(10, 0)).catch(console.error)
// Output: (FiberFailure) Error: Division by zero
The type signature Effect<number, string, never> tells you:
  • Returns a number on success
  • Fails with a string error
  • Requires no dependencies (never)
4

Compose Multiple Effects

Chain effects together naturally using yield*:
import { Effect, Console } from "effect"

const program = Effect.gen(function* () {
  yield* Console.log("Starting computation...")
  
  const x = yield* Effect.succeed(10)
  const y = yield* Effect.succeed(20)
  const result = yield* divide(x + y, 2)
  
  yield* Console.log(`Result: ${result}`)
  return result
})

Effect.runPromise(program).then(console.log)
// Output:
// Starting computation...
// Result: 15
// 15

Working with Promises

Effect makes it easy to work with existing Promise-based code:
import { Effect } from "effect"

// Convert a Promise to an Effect
const fetchData = Effect.tryPromise({
  try: () => fetch("https://api.example.com/data").then(r => r.json()),
  catch: (error) => new Error(`Failed to fetch: ${error}`)
})

const program = Effect.gen(function* () {
  const data = yield* fetchData
  return data
})

Effect.runPromise(program).then(console.log).catch(console.error)
The tryPromise function converts a Promise into an Effect, allowing you to specify how to handle rejection errors.

Error Recovery

Effect provides powerful error recovery operators:
import { Effect } from "effect"

const task = Effect.gen(function* () {
  return yield* Effect.fail("Something went wrong")
})

// Provide a fallback value
const recovered = task.pipe(
  Effect.catchAll(() => Effect.succeed("Fallback value"))
)

Effect.runPromise(recovered).then(console.log)
// Output: Fallback value

Next Steps

Now that you’ve written your first Effect program, explore these topics:

Error Handling

Master type-safe error handling patterns

Concurrency

Learn about fibers and concurrent execution

Dependency Injection

Build modular applications with Context and Layer

Resource Management

Safely manage resources with automatic cleanup
The Effect type signature Effect<A, E, R> is your guide:
  • A: What succeeds
  • E: What fails
  • R: What’s required

Build docs developers (and LLMs) love