typescript-patterns

Apply branded types, discriminated unions, and type guards to TypeScript projects.

5|Updated Nov 18, 2025
One-click install
npx skills add https://github.com/duyet/duyetbot-agent --skill typescript-patterns-duyet
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: typescript-patterns
Source: https://github.com/duyet/duyetbot-agent/tree/main/apps/duyetbot-action/.claude/skills/typescript-patterns
Command: npx skills add https://github.com/duyet/duyetbot-agent --skill typescript-patterns-duyet

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps developers enforce safer TypeScript code by applying proven typing patterns across codebases, reducing runtime errors and increasing maintainability.

Core Features & Use Cases

  • Branded Types for Domain Safety: create type-safe identifiers that prevent mixing entities.
  • Discriminated Unions for State: implement exhaustive, safe state machines.
  • Type Guards and Runtime Validation: verify types at runtime to prevent invalid data flows.
  • Utility Types and Advanced Patterns: leverage DeepPartial, RequireFields, and other helpers for robust type definitions.
  • Error Handling Patterns: design a typed error hierarchy and safe error handling strategies.
  • General Pattern Catalog: repository and builder patterns for scalable TypeScript code.

Quick Start

Prompt the AI to generate a type-safe module skeleton for a small domain (e.g., User and Order) using branded IDs, discriminated unions, and a minimal error class hierarchy, then adapt it to your project.

Frequently Asked Questions about typescript-patterns

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

FAQPage Schema
How do I use branded types in TypeScript to prevent mixing entity IDs?

Discriminated unions implement exhaustive, safe state machines by defining a common literal property across types. This allows TypeScript to safely narrow state and guarantee all possible cases are handled.

What is the best way to structure a typed error hierarchy in TypeScript?

A typed error hierarchy structures error classes to provide safe error handling strategies. It categorizes runtime exceptions into distinct types, allowing precise error identification and structured recovery flows.

Can I use TypeScript utility types like DeepPartial for robust domain modeling?

Yes, utility types like DeepPartial and RequireFields provide robust type definitions for domain modeling. They help create flexible yet safe data structures by selectively modifying existing type constraints.

How do I implement runtime type guards for API typings in JavaScript applications?

Runtime type guards verify types dynamically to prevent invalid API data flows. By validating external API typings against expected structures, you ensure invalid data is caught before entering the application state.

When do I need discriminated unions for state management?

Discriminated unions are needed for state management when implementing exhaustive, safe state machines. They ensure that all state transitions are explicitly typed and handled without missing cases.