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.