typescript-patterns

Apply TypeScript type design patterns for type-safe, IDE-friendly code.

1|Updated Feb 15, 2026
One-click install
npx skills add https://github.com/p-iknow/fullstack-forge --skill typescript-patterns-p-iknow
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: typescript-patterns
Source: https://github.com/p-iknow/fullstack-forge/tree/main/.claude/skills/typescript-patterns
Command: npx skills add https://github.com/p-iknow/fullstack-forge --skill typescript-patterns-p-iknow

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This skill provides a concise set of TypeScript type design patterns and guidance to make component props, domain states, and runtime-validated types safer, easier to author, and IDE-friendly. It prevents common pitfalls such as bags of optional fields, brittle enums, and divergence between runtime schemas and static types.

Core Features & Use Cases

  • Predefined values with flexibility: recommend a small set of predefined values while allowing arbitrary inputs and mapping predefined values to optimized runtime handling.
  • Discriminated unions for domain state: model mutually exclusive states so each variant carries only relevant data and exhaustiveness checks prevent missing cases.
  • String literal flexibility and enum replacement: provide IDE suggestions for known strings while accepting custom values and prefer const objects with derived types over TypeScript enums.
  • Zod schema inference: derive static types from runtime validation schemas to keep a single source of truth for validation and typing. Use case: apply these patterns when designing UI component props, modeling API or domain states, or deriving API contract types from validation schemas to improve developer ergonomics and runtime correctness.

Quick Start

Use the typescript-patterns guidance to convert a component prop definition into a predefined-value pattern, a discriminated union, or a Zod-derived type.

Frequently Asked Questions about typescript-patterns

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

FAQPage Schema
How do I model mutually exclusive domain states in TypeScript?

TypeScript discriminated unions model mutually exclusive domain states by giving each variant a unique literal type property, ensuring that each state carries only its relevant data and enabling exhaustive switch narrowing.

What is the best way to replace TypeScript enums with IDE-friendly types?

Replacing TypeScript enums is best done using const objects with derived types, which provide IDE autocomplete suggestions for known strings while accepting custom values and avoiding brittle runtime enum behavior.

How do I derive API types from Zod schemas for a single source of truth?

Deriving API types from Zod schemas uses Zod's schema inference to generate static TypeScript types directly from runtime validation rules, keeping validation and type definitions in a single source of truth.

How do I define component prop types with predefined values but flexible inputs?

Defining component prop types with predefined values involves using string literal types to suggest a small set of known values while still allowing arbitrary string inputs and mapping them to optimized runtime handling.

Why does my TypeScript discriminated union fail exhaustiveness checks?

Discriminated union exhaustiveness checks fail when switch statements do not cover every variant's literal type property, which can be prevented by applying a never type check to catch missing domain state cases.