explaingit

gcanti/fp-ts

11,510TypeScriptAudience · developerComplexity · 3/5Setup · moderate

TLDR

A TypeScript library that adds functional programming building blocks like Option, Either, IO, and Task, so you can handle missing values, errors, and async operations without null checks or thrown exceptions.

Mindmap

mindmap
  root((fp-ts))
    What it does
      Functional patterns
      Error handling
      Async control
    Core Types
      Option
      Either
      IO
      Task
    Tech Stack
      TypeScript
      npm
    Audience
      TypeScript developers
      FP practitioners
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Replace null and undefined checks with the Option type so all callers are forced to handle missing values explicitly

USE CASE 2

Use Either to model success-or-failure results in data transformations without ever throwing an exception

USE CASE 3

Chain async operations with Task so side effects are isolated, composable, and predictable

Tech stack

TypeScriptnpm

Getting it running

Difficulty · moderate Time to first run · 1h+

Requires TypeScript strict mode and TypeScript 3.5+, note that fp-ts is merging into Effect-TS, new projects should consider Effect-TS instead.

In plain English

fp-ts is a TypeScript library that brings a style of programming called functional programming into the TypeScript world. Functional programming is an approach to writing software that originated in academic languages like Haskell and Scala, where code is structured around pure functions and specific patterns for handling uncertainty, errors, and asynchronous operations in a very controlled way. The library provides a set of building blocks with names like Option, Either, IO, and Task. Option represents a value that might or might not exist, avoiding the need to check for null or undefined manually. Either represents a result that is either a success or a failure, giving you a structured way to handle errors without exceptions. IO and Task handle operations that have side effects or run asynchronously. These building blocks can be composed together in predictable ways. One technical note from the README: TypeScript does not natively support a feature called Higher Kinded Types, which is required to express some of these functional patterns properly. fp-ts works around that limitation with its own encoding. The library requires TypeScript's strict mode to be enabled and works with TypeScript 3.5 and above. It is installed from npm with a single command. The README also announces that fp-ts is merging with a related project called Effect-TS. The author of fp-ts is joining the Effect organization, and Effect-TS is described as the successor to fp-ts, representing what would have been version 3. New projects are directed toward Effect-TS rather than continuing with fp-ts directly. The documentation for fp-ts explicitly states that teaching functional programming is outside its scope, so it is aimed at developers who already understand what functional programming is and want to apply its patterns in TypeScript.

Copy-paste prompts

Prompt 1
Show me how to use fp-ts Either to safely parse user input and return a structured error instead of throwing an exception in TypeScript.
Prompt 2
I have a TypeScript function that returns null when a record isn't found. Refactor it using fp-ts Option so all callers must handle the missing case.
Prompt 3
How do I compose multiple fp-ts Task operations in sequence so that a failure in one step short-circuits the rest of the chain?
Prompt 4
My TypeScript project needs strict error handling with no exceptions anywhere. Walk me through adopting fp-ts Either and Option across an existing codebase.
Open on GitHub → Explain another repo

← gcanti on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.