fp-ts is a TypeScript library providing tools for typed functional programming, including popular algebraic data types like `Option`, `Either`, `IO`, and `Task`, alongside type classes such as `Functor`, `Applicative`, and `Monad`. It uniquely implements Higher Kinded Types to enable robust functional patterns within TypeScript's type system. The current stable version is 2.16.11, last published approximately 8 months ago as of the current date. While actively maintained, recent announcements indicate that the `fp-ts` project is officially merging with the Effect-TS ecosystem, with Effect-TS being positioned as the successor, akin to `fp-ts v3`. This transition implies a future shift in development focus towards the Effect-TS project, offering enhanced capabilities and support for new users.
npm install fp-tsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates fetching data, parsing JSON, and safely accessing optional properties using `TaskEither`, `Either`, `Option`, and the `pipe` function for functional composition and error handling. It shows how to chain operations that can fail (HTTP request, JSON parsing) and gracefully handle missing values.
For new projects or major architectural shifts, consider starting with Effect-TS. For existing `fp-ts v2` projects, continue with `fp-ts` for now, but be aware of the long-term migration path to Effect-TS. Review Effect-TS documentation for compatibility and migration guides.
Use `npm ls fp-ts` to check installed versions and ensure only one `fp-ts` version is present, or that others are `deduped`. Resolve conflicting dependencies by adjusting package versions or using `npm dedupe`.
Enable the `strict` flag in your `tsconfig.json` to ensure full type safety and compatibility with fp-ts's design principles.
Replace calls to `chain` or `chainW` with their `flatMap` equivalents. For example, `pipe(optionValue, O.chain(f))` becomes `pipe(optionValue, O.flatMap(f))`.
Update usage from `mapLeft` to `mapError` and `bimap` to `mapBoth` where applicable to align with the latest API naming conventions.
Avoid using `fp-ts@2.13.0`. Upgrade to `2.13.1` or newer immediately if you encounter module resolution issues related to this version.
Run `npm ls fp-ts` to identify duplicate versions. Use `npm dedupe` or manually adjust your `package.json` dependencies to ensure only a single `fp-ts` version is installed and deduped.
Migrate your imports to ESM syntax: `import { pipe } from 'fp-ts/function';` instead of `const { pipe } = require('fp-ts/function');`.Ensure you are using the correct import path `import { pipe } from 'fp-ts/function';`. Verify your `tsconfig.json` `moduleResolution` and `module` settings are compatible with modern Node.js or your bundler (e.g., `"moduleResolution": "bundler"` or `"node16"`).Enable `"strict": true` in your `tsconfig.json`. Ensure all possible cases of ADTs (e.g., `None`/`Some` for `Option`, `Left`/`Right` for `Either`) are handled using `match`, `fold`, or type guards.
No dependency data recorded yet.