functional-typescript-ts-patternlisted
Install: claude install-skill yutna/functional-design-skills
# Functional TypeScript With ts-pattern
## Overview
`ts-pattern` supplies the one construct TypeScript lacks: pattern
matching over the shape of a value, with an exhaustiveness check the
compiler enforces. Everything the core skills say about choice types and
state machines becomes easier to express, because matching on nested
structure no longer needs a chain of narrowing conditions.
It changes how code is written, not what the design is. The types come
from
[functional-typescript](../functional-typescript/SKILL.md); this pack
covers how to consume them.
**Check the installed version before writing code.** The shapes below
target ts-pattern 5.
## When to use
- A TypeScript project that already depends on ts-pattern
- Dispatching over a discriminated union, especially on nested fields
- Implementing a state machine's transitions
- Handling a `Result` or a union of errors
Not for: designing the union itself, which is
[functional-modeling-with-algebraic-types](../functional-modeling-with-algebraic-types/SKILL.md).
## Core rules
1. Rule. **End every match with `.exhaustive()`.** That is the whole point;
`.otherwise()` throws the guarantee away.
2. Default. **Match on the discriminant first**, then on nested structure, so
the patterns read in the order a person would ask the questions.
3. Default. **Use `P.when` for guards**, not for business rules that deserve a
name. A guard should fit on a line.
4. Default. **Select what you use.** `P.select()` names the part