functional-ts

Model TypeScript domain state with discriminated unions and pure functions.

51|2|Updated Apr 7, 2026
One-click install
npx skills add https://github.com/iwasa-kosui/functional-ts-principles --skill functional-ts
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: functional-ts
Source: https://github.com/iwasa-kosui/functional-ts-principles/tree/main/skills/functional-ts
Command: npx skills add https://github.com/iwasa-kosui/functional-ts-principles --skill functional-ts

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Domain modeling in server-side TypeScript often becomes brittle when using classes; this Skill provides a functional approach using discriminated unions, pure functions, and Result types to ensure safer, more maintainable domain logic.

Core Features & Use Cases

  • Discriminated unions for state modeling with kind as discriminant.
  • Pure state transitions as deterministic functions.
  • Error handling with Result types and exhaustive error typing.
  • Validation boundary integration and PII protection with Sensitive type.
  • Use cases include modeling workflows like taxi dispatch, order processing, and API boundaries.

Quick Start

Create a simple domain with Waiting and EnRoute states and demonstrate a pure transition from Waiting to EnRoute when a driver is assigned.

Frequently Asked Questions about functional-ts

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

FAQPage Schema
How do I model domain state transitions in TypeScript without classes?

Model domain state transitions in TypeScript by using discriminated unions with a kind property for state and pure functions for deterministic transitions. This functional approach replaces brittle class-based state management with safer, more maintainable domain logic.

What is the best way to handle errors functionally in TypeScript domain modeling?

Handle errors functionally in TypeScript domain modeling using Railway Oriented Programming with Result types. This enforces exhaustive error typing and safe state transitions without relying on exceptions for control flow.

How does discriminated union domain modeling work for server-side TypeScript?

Discriminated union domain modeling in server-side TypeScript works by defining states with a discriminant property like kind. Pure functions then handle transitions between states such as Waiting and EnRoute, ensuring deterministic and type-safe workflows.

Can I protect PII data types in TypeScript domain models?

Protect PII data types in TypeScript domain models using a Sensitive type at validation boundaries. This ensures personally identifiable information is explicitly marked and safeguarded during functional domain state transitions and use case processing.

Does functional domain modeling work for complex workflows like order processing?

Functional domain modeling works for complex workflows like order processing and taxi dispatch. By applying pure functions, Result types, and boundary validation, use cases and domain events remain safe, readable, and maintainable across server-side operations.

Why should I use pure functions instead of classes for TypeScript domain logic?

Use pure functions instead of classes for TypeScript domain logic to ensure deterministic state transitions and avoid brittle class hierarchies. Functional domain modeling with Result types and discriminated unions improves safety and readability.