ts-patterns

Enforce strict TypeScript patterns with discriminated unions and branded types.

1|Updated Mar 4, 2026
One-click install
npx skills add https://github.com/yandy-r/claude-plugins --skill ts-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ts-patterns
Source: https://github.com/yandy-r/claude-plugins/tree/main/.cursor-plugin/skills/ts-patterns
Command: npx skills add https://github.com/yandy-r/claude-plugins --skill ts-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Writing safe, maintainable TypeScript code can be error-prone without clear idioms. This Skill provides a curated set of patterns and ergonomics to enforce strong types, predictable APIs, and cross-runtime compatibility.

Core Features & Use Cases

  • Strict by default TypeScript design and inference-first APIs to minimize annotation burden.
  • Patterns like discriminated unions, branded types, and satisfies to preserve literals and ensure exhaustiveness.
  • Guidance for ESM/CJS dual publishing with exports maps for dual publishing.

Quick Start

Enable strict TypeScript in your tsconfig and begin applying these idioms across your codebase.

Frequently Asked Questions about ts-patterns

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

FAQPage Schema
What's the best way to ensure exhaustive type checking in TypeScript?

Exhaustive type checking in TypeScript is best achieved using discriminated unions, which enforce literal preservation and ensure all possible union cases are handled. This pattern prevents unhandled states and improves runtime safety.

How do I preserve literal types in TypeScript without losing inference?

Use the satisfies operator in TypeScript to preserve literal types without widening them during assignment. It validates that an object conforms to a specific type while retaining the original literal values for stricter downstream inference.

When do I need branded types in TypeScript?

Branded types are needed in TypeScript when you must distinguish structurally identical types, like a UserId and a ProductId string. They prevent accidental cross-assignment and enforce domain-specific type safety.

Can I use these TypeScript patterns across Node, Deno, and Bun runtimes?

Yes, these TypeScript patterns apply to library and application code across Node, Deno, Bun, browser, and edge runtimes. They focus on strict configurations and type-level logic independent of the JavaScript runtime environment.

How do I configure an exports map for ESM and CJS dual publishing?

Configure an exports map in your package.json to define separate entry points for ESM and CJS dual publishing. This ensures consumers receive the correct module format based on their TypeScript runtime environment and module resolution settings.

Why should I enable strict mode by default in my TypeScript configuration?

Enabling strict mode by default in TypeScript catches implicit any types and null reference errors early. It forms the foundation for an inference-first API design that minimizes annotation burden and maximizes type safety.