Skip to content

Data Types

Effect ships a small set of immutable, value-oriented data types that show up everywhere in real code. They are plain data — pure, structurally comparable, and safe to share — and many of them interoperate directly with Effect (an Option or a Result can be yield*-ed inside Effect.gen).

This section covers the types you reach for most often:

  • Option — model a value that may be absent (Some<A> or None) instead of using null/undefined.
  • Result — a synchronous success-or-failure value (Success<A, E> or Failure<A, E>). This is v4’s replacement for Either.
  • Exit and Cause — the full result of running an effect: a success value, or a Cause that captures expected failures, defects, and interruptions.
  • Chunk — an immutable, high-performance sequence used throughout Streaming.
  • Data — base classes that give your structs and tagged unions automatic value equality.
  • DateTime and Duration — time-zone aware instants and a precise representation of spans of time.
  • BigDecimal — arbitrary-precision decimal arithmetic without floating-point rounding errors.
  • Brand — nominal types that distinguish values sharing the same underlying representation (e.g. UserId vs number).
  • Redacted — wrap secrets so they never leak into logs, errors, or stack traces.

Two themes recur across these types and explain why Effect prefers them over raw JavaScript primitives:

Absence and failure are values, not exceptions. Rather than throwing or returning null, partial computations return an Option or a Result. The type signature then tells the truth about what can happen, and the compiler forces you to handle every case.

Equality is structural. Types built on Data (and Chunk, Option, Result, Duration, …) compare by value, not by reference. Two separately constructed instances holding the same data are Equal.equals, which makes them safe to use as keys in HashMap/HashSet and to compare in tests.

import { Data, Equal } from "effect"
class Point extends Data.Class<{ readonly x: number; readonly y: number }> {}
// Two distinct objects, structurally equal
console.log(Equal.equals(new Point({ x: 1, y: 2 }), new Point({ x: 1, y: 2 })))
// Output: true

Pick the page for the type you need — each one leads with a realistic example and explains the operations you will actually use.