typescript:functional-patterns

Model TypeScript domain logic with ADTs, Option/Result, and branded types.

39|4|Updated Jan 11, 2026
One-click install
npx skills add https://github.com/martinffx/atelier --skill typescript-functional-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: typescript:functional-patterns
Source: https://github.com/martinffx/atelier/tree/main/skills/typescript%3Afunctional-patterns
Command: npx skills add https://github.com/martinffx/atelier --skill typescript-functional-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Model and enforce safe, reliable domain logic in TypeScript using ADTs, Option/Result, and branded types.

Core Features & Use Cases

  • Discriminated unions and Algebraic Data Types for exhaustive state modeling
  • Option and Result types for explicit error handling and nullable values
  • Branded types for domain invariants (IDs, units, and validated values)
  • Practical guidance for pattern usage in real-world scenarios such as state machines, configuration parsing, and safe migrations

Quick Start

Create a small TypeScript example showing a discriminated union and an exhaustive switch to model a simple traffic-light state.

Frequently Asked Questions about typescript:functional-patterns

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

FAQPage Schema
How do I model exhaustive state machines in TypeScript?

Use discriminated unions and Algebraic Data Types (ADTs) to model exhaustive state machines in TypeScript. Apply an exhaustive switch statement with an assertNever utility to enforce compile-time guarantees across all possible states.

What is the best way to handle nullable values and errors in TypeScript domain logic?

The best way to handle nullable values and errors in TypeScript domain logic is using Option and Result types. These utilities provide explicit error handling, forcing callers to safely resolve operations without relying on exceptions or null checks.

How do I enforce domain invariants like validated IDs and units at compile time?

Enforce domain invariants like validated IDs and units at compile time by using branded types in TypeScript. This pattern tags primitive values with structural markers, ensuring only validated data passes through your domain models.

Can I use discriminated unions for safe data parsing and configuration migrations?

Yes, you can use discriminated unions for safe data parsing and configuration migrations. They enable strict pattern matching and compile-time exhaustiveness checks, preventing unhandled states during data transformations and safe migrations.

When should I not use Result types for error handling in TypeScript?

You should avoid Result types when migrating existing codebases that heavily rely on try-catch exception handling, as mixing both patterns can complicate logic. Result types work best for predictable, recoverable domain errors rather than unexpected runtime failures.