API Reference

fp-ts

Functional programming library for TypeScript providing Option, Either, Task, and composable pipes.

Official Documentation ↗
CompatibilityThis documentation covers version v2. Check the official docs for the latest API surface.

Installation

npmnpm install fp-ts
pnpmpnpm add fp-ts

Methods

Functional programming library for TypeScript providing Option, Either, Task, and composable pipes.

Overview

fp-ts is the long-standing functional toolkit for TypeScript: Option for absence, Either for typed success or failure, Task and TaskEither for async, and pipe for left-to-right composition. The module structure imports only what you use.

Its combinators enable railway-style pipelines where error handling is declared once and applied along the chain. Typeclass interfaces make generic helpers reusable, and the patterns transfer directly to newer effect systems.

Core Methods

The most frequently used entry points, with signatures and runnable examples:

  • Option — Models a value that may be absent without null checks; match handles both branches.
  • Either — Models a success or typed failure; the left channel carries the error type.
  • pipe — Threads a value through functions in reading order, the backbone of fp-ts composition.
  • TaskEither — Async computations that fail into a typed left channel instead of rejected promises.

Usage Notes

  • Adopt Option and Either at system boundaries first, then expand inward.
  • Compose with pipe rather than nested calls for readability and inference.
  • Name pipeline stages; anonymous chains become hard to review.

Common Pitfalls

  • Mixing Task and TaskEither forces conversions; standardize on TaskEither for fallible work.
  • Importing from fp-ts root pulls the entire library; use module paths like fp-ts/Either.
  • Deep abstraction layers can outpace team familiarity and stall reviews.

FAQ

How is fp-ts different from Effect?
Effect is the successor effort led by the same community, unifying errors, retries, concurrency, and DI with stronger runtime support. fp-ts remains a stable, smaller toolkit focused on data types and pure composition, and many codebases still run it in production.
Why pipe instead of nesting?
Nested calls read inside-out and refactor painfully. pipe keeps the data-first reading order, lets TypeScript infer intermediate types, and composes with any unary function, not only fp-ts combinators.
How steep is the learning curve?
Option, Either, and pipe cover most value quickly. The deeper abstractions, traversable, Semigroup, monad transformers, take study. Introduce the data types at boundaries first and let the team grow into the rest.