typescript-patterns

Guide advanced TypeScript patterns for type safety and code quality.

42|5|Updated Mar 8, 2026
One-click install
npx skills add https://github.com/kazdenc/builder-skills --skill typescript-patterns-kazdenc
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: typescript-patterns
Source: https://github.com/kazdenc/builder-skills/tree/main/.claude/skills/dev/frameworks/typescript-patterns
Command: npx skills add https://github.com/kazdenc/builder-skills --skill typescript-patterns-kazdenc

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps developers write more robust, maintainable, and type-safe TypeScript code by applying advanced design patterns and best practices.

Core Features & Use Cases

  • Type Safety: Enforces compile-time checks to prevent runtime errors.
  • Advanced Patterns: Covers branded types, generics, utility types, discriminated unions, and effective error handling.
  • Use Case: When refactoring a complex JavaScript module to TypeScript, use this Skill to ensure all types are correctly defined and constraints are properly applied, preventing regressions.

Quick Start

Apply the branded types pattern to distinguish between UserId and OrderId in your TypeScript 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 discriminated unions for error handling in TypeScript?

Discriminated unions enhance TypeScript error handling by creating mutually exclusive object shapes with a common literal property. This enables safe type narrowing within switch statements, ensuring all error variants are handled at compile time.

What are branded types and how do they improve type safety?

Branded types improve type safety by creating nominally typed primitives that prevent accidental mixing of structurally identical values. They distinguish identifiers like UserId and OrderId at compile time, eliminating invalid assignments.

What is the best way to refactor JavaScript to TypeScript without regressions?

Refactoring JavaScript to TypeScript requires applying advanced patterns like generics and utility types to define strict constraints. This enforces compile-time checks that prevent runtime errors and secure complex module migrations.

How do TypeScript utility types and generics work together?

TypeScript utility types and generics work together by transforming existing type definitions into flexible, reusable constraints. Generics capture dynamic types while utility types manipulate them, enforcing compile-time checks across reusable components.

When should I use advanced TypeScript patterns instead of basic type annotations?

Use advanced TypeScript patterns when basic annotations fail to capture complex domain constraints. Patterns like generics and discriminated unions are essential for writing robust, maintainable codebases that require strict compile-time error prevention.