fp-ts Option and Either

Convert nullables to Option and propagate typed errors with fp-ts Either.

11|3|Updated Jan 30, 2026
One-click install
npx skills add https://github.com/whatiskadudoing/fp-ts-skills --skill fp-ts-option-and-either
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: fp-ts Option and Either
Source: https://github.com/whatiskadudoing/fp-ts-skills/tree/main/skills/fp-option-either
Command: npx skills add https://github.com/whatiskadudoing/fp-ts-skills --skill fp-ts-option-and-either

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides safe handling of nullable values and errors in TypeScript by leveraging fp-ts Option and Either, reducing runtime issues and improving type safety.

Core Features & Use Cases

  • Option-based handling for nullable values, reducing undefined checks.
  • Either-based error propagation with typed failures, enabling robust validation flows.
  • Seamless composition with pipe and functional utilities to build readable pipelines.
  • Use case: convert a nullable user id to an Option and then validate it with typed errors.

Quick Start

Install fp-ts and import the modules. Convert a nullable value to an Option using fromNullable and extract with getOrElse. Create and transform Either values with right/left and map/chain as needed.

Frequently Asked Questions about fp-ts Option and Either

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I handle nullable values safely in TypeScript using fp-ts?

To handle nullable values safely in TypeScript, convert them to Option using fp-ts fromNullable. This wraps undefined values in a typed structure, allowing you to extract them safely using getOrElse and avoid runtime errors.

What is the best way to propagate typed errors in TypeScript validation flows?

The best way to propagate typed errors in TypeScript is by using fp-ts Either. By returning right for success and left for failure, you can build robust validation flows that force explicit error handling at compile time.

How do I compose functional pipelines for error handling in TypeScript?

To compose functional pipelines for error handling in TypeScript, use fp-ts pipe with map and chain. This allows you to sequence operations that might fail, passing Either or Option values through readable transformations.

Does fp-ts Option work with fromPredicate for input validation?

Yes, fp-ts Option works with fromPredicate for input validation. You can use fromPredicate to check if a value meets specific criteria, automatically wrapping valid inputs in an Option and returning none if the condition fails.

When should I use fold with fp-ts Either and Option?

You should use fold with fp-ts Either and Option when you need to extract a final value from a pipeline. Fold forces you to handle both the success and failure cases, ensuring safe unwrapping of the monadic value.