type-patterns

Implement typed Result<T, E> and discriminated unions for TypeScript error handling.

Updated Jan 2, 2026
One-click install
npx skills add https://github.com/Higashi-Kota/llm-mermaid-chat --skill type-patterns
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: type-patterns
Source: https://github.com/Higashi-Kota/llm-mermaid-chat/tree/main/.claude/skills/type-patterns
Command: npx skills add https://github.com/Higashi-Kota/llm-mermaid-chat --skill type-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill helps developers replace throw-based error handling with a typed Result type and discriminated unions, enabling safer and more predictable control flow in TypeScript.

Core Features & Use Cases

  • Type-Safe Result type and discriminated unions for error modeling.
  • Exhaustive pattern matching with ts-pattern to guarantee all cases are handled.
  • Patterns for immutable data handling and safer domain logic across APIs, validation, and data transformations.

Quick Start

Try implementing a function that returns a Result<number, AppError> instead of throwing, and demonstrate exhaustive handling with ts-pattern in the caller.

Frequently Asked Questions about type-patterns

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

FAQPage Schema
How do I handle errors in TypeScript without throwing exceptions?▼

Type-safe error handling in TypeScript replaces throw-based exceptions with a typed Result<T, E> pattern and discriminated unions, enabling safer and more predictable control flow for application logic.

What is the best way to ensure exhaustive error handling in TypeScript?▼

The best way to ensure exhaustive error handling in TypeScript is by combining discriminated unions for AppError variants with ts-pattern for exhaustive pattern matching, guaranteeing all error cases are handled.

How do I use a Result type for data fetching and validation in TypeScript?▼

You can use a Result type for data fetching and validation by returning Result<T, AppError> instead of throwing, then applying exhaustive matching with ts-pattern in the caller to handle success and error states explicitly.

Does ts-pattern work with discriminated unions for domain modeling?▼

Yes, ts-pattern works with discriminated unions for domain modeling by enabling exhaustive pattern matching, which guarantees all cases are handled safely across APIs, validation, and data transformations.

When should I replace throw-based error handling with a Result type?▼

You should replace throw-based error handling with a Result type when building application logic requiring robust error handling, domain modeling, and exhaustive case analysis for data fetching, validation, and transformation.