Dev.to
5/12/2026

Why I built ts-match: TypeScript branching in the era of coding agents
Short summary
The author introduces ts-match, a TypeScript library that simplifies pattern matching on discriminated unions—especially useful for agent event handling. It uses a fluent API to make branching logic more readable than switch statements while maintaining full type safety. Already proven in OpenWaggle, an open-source coding agent, where it manages complex event streams and state transitions.
- •ts-match provides a fluent API for cleaner pattern matching on TypeScript discriminated unions
- •Improves code readability over switch statements while preserving full type safety
- •Validated in OpenWaggle for managing complex agent event streams and state transitions
Generated with AI, which can make mistakes.
Is this a good recommendation for you?



