typescript-best-practices
Use when reading or writing TypeScript or JavaScript files (.ts, .tsx, .js, tsconfig.json).
By alleneubank · 3,294 installs
npx skills add alleneubank/claude-code --skill typescript-best-practices
Source repository · Upstream listing
TypeScript Best Practices
Follows type first, functional, and error handling patterns from CLAUDE.md. This skill covers language specific idioms only.
Pair with React Best Practices
When working with React components ( .tsx , .jsx files or @react imports), always load react best practices alongside this skill. This skill covers TypeScript fundamentals; React specific patterns (effects, hooks, refs, component design) are in the dedicated React skill.
Make Illegal States Unrepresentable
Use the type system to prevent invalid states at compile time.
Discriminated unions for mutually exclusive states:
Branded types for domain primitives:
Const assertions for literal unions:
Exhaustive switch with never check:
Runtime Validation with Zod
Define schemas as single source of truth; infer TypeScript types with z.infer< . Avoid duplicating types and schemas.
Use safeParse for user input where failure is expected; use parse at trust boundaries where invalid data is a bug.
Compose schemas with .extend() , .pick() , .omit() , .merge() for DRY definitions.
Add .transform() for data normalization at parse time (trim strings, parse dates).
Optional: type fest
For advanced type utilities beyond TypeScript builtins, consider [type fest](https://github.com/sindresorhus/type fest):
Opaque<T, Token cleaner branded types than manual & { brand } pattern
PartialDeep<T recursive partial for nested objects
ReadonlyDeep<T recursive readonly for immutable data
SetRequired<T, K / SetOptional<T, K targeted field modifications
Simplify<T flatten complex intersection types in IDE tooltips