ts-match

Provides TypeScript pattern matching, exhaustive union checks, and runtime validation via match, exhaustive, isMatching APIs.

4|1|Updated Feb 17, 2026
One-click install
npx skills add https://github.com/OpenWaggle/OpenWaggle --skill ts-match
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ts-match
Source: https://github.com/OpenWaggle/OpenWaggle/tree/main/.agents/skills/ts-match
Command: npx skills add https://github.com/OpenWaggle/OpenWaggle --skill ts-match

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @diegogbrisa/ts-match, and includes scripts (resource) components.

What problem does it solve?

This Skill helps TypeScript developers perform pattern matching, exhaustive union handling, and runtime validation efficiently, reducing boilerplate and errors.

Core Features & Use Cases

  • Pattern Matching: Provides APIs like match, match.promise, and matchBy to handle complex conditional logic based on object structure, discriminated unions, and paths.
  • Type Safety & Exhaustiveness: Ensures comprehensive coverage with exhaustive() checks, preventing unhandled cases in TypeScript projects.
  • Runtime Validation: Offers guards like isMatching and assertMatching to validate data objects at runtime, throwing detailed errors when mismatched.
  • Use Case: Developers can parse API responses, configuration objects, or state machines with concise, type-safe code, and catch errors early during development.

Quick Start

Use the ts-match library to handle pattern matching for API response parsing or discriminated union handling in TypeScript.

Frequently Asked Questions about ts-match

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

FAQPage Schema
How do I perform pattern matching in TypeScript for complex conditional logic?

Use `match`, `matchBy`, and `match.promise` APIs to handle TypeScript pattern matching based on object structure and discriminated unions. This reduces boilerplate and improves code clarity for complex conditional logic.

How can I ensure exhaustive union checks in my TypeScript codebase?

Use the `exhaustive()` check to ensure comprehensive coverage of all possible cases in discriminated unions. This prevents unhandled scenarios and enhances type safety across your TypeScript codebase.

What is the best way to validate API responses at runtime in TypeScript?

Validate API responses at runtime using `isMatching` and `assertMatching` guards to check data objects against expected patterns. They throw detailed errors when data mismatches occur, catching issues early.

Does ts-match support promise-aware matching for asynchronous operations?

Yes, it supports promise-aware matching via the `match.promise` API. This allows developers to handle asynchronous operations and conditional logic seamlessly within TypeScript pattern matching workflows.

How do I handle nested discriminant paths when parsing configuration objects?

Leverage the library's pattern matching capabilities to handle nested discriminant paths when parsing configuration objects. This ensures data integrity and type-safe control flow for deeply nested structures.

Why should I use a pattern matching library instead of standard switch statements?

A pattern matching library reduces boilerplate and errors compared to standard switch statements. It provides robust type inference, runtime validation guards, and exhaustive union checks that standard TypeScript conditionals lack.