pattern-matching

Match TypeScript discriminated unions exhaustively with Effect's Data.TaggedEnum and $match.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/front-depiction/claude-setup --skill pattern-matching
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pattern-matching
Source: https://github.com/front-depiction/claude-setup/tree/main/skills/pattern-matching
Command: npx skills add https://github.com/front-depiction/claude-setup --skill pattern-matching

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Developers struggle with writing exhaustive, type-safe pattern matching for discriminated unions in TypeScript. This Skill provides guidance and patterns to use Data.TaggedEnum, $match, and related helpers to write declarative, compiler-checked branches across all variants.

Core Features & Use Cases

  • Exhaustive, type-safe pattern matching across ADTs with Data.TaggedEnum
  • Nested matches and multi-variant refinement using $match and $is
  • Real-world scenarios: state machines, domain events, and result types

Quick Start

Define a TaggedEnum-based union, then apply WalletState.$match(state, { ... }) to handle every variant.

  • User instruction: Show how to pattern match a WalletState with variants Disconnected, Connecting, Connected, and Error using the $match helper.

Frequently Asked Questions about pattern-matching

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

FAQPage Schema
How do I write exhaustive, type-safe pattern matching for discriminated unions in TypeScript?

Exhaustive, type-safe pattern matching for discriminated unions in TypeScript is achieved using Effect's Data.TaggedEnum and the $match helper to enforce compiler-checked branches across all variants. This approach replaces manual switch statements with declarative, pipeline-friendly patterns.

Does Effect Data.TaggedEnum support nested matches and multi-variant type refinement?

Yes, Effect Data.TaggedEnum supports nested matches and multi-variant type refinement using the $match and $is helpers. This allows developers to declaratively refine types across complex ADT variants while maintaining compiler-checked exhaustiveness.

What is the best way to handle state machine variants like Disconnected or Connecting in TypeScript?

The best way to handle state machine variants like Disconnected or Connecting is by defining a TaggedEnum-based union and applying the $match helper with handlers for each state. This ensures declarative, exhaustive type safety across all domain states.

How do I enforce compiler-checked exhaustiveness when matching domain events in TypeScript?

Compiler-checked exhaustiveness for domain events is enforced by defining events with Data.TaggedEnum and using $match to handle every variant. The TypeScript compiler will raise an error if any union variant is missing from the match pattern.

Can I use $match pipelines for result types without losing type safety in Effect?

Yes, you can use $match pipelines for result types in Effect without losing type safety. The $match helper integrates into declarative pipelines to refine types securely, ensuring that all possible result variants are matched exhaustively.

Why does my TypeScript discriminated union match fail to catch missing variants?

A discriminated union match fails to catch missing variants when not using exhaustive helpers like Effect's $match. By defining unions with Data.TaggedEnum and applying $match, the compiler is forced to verify that every variant has a corresponding handler.