# Typescript Best Practices

> Apply disciplined TypeScript modeling and boundary parsing. Use when reading or editing TypeScript.

- Skill: `theonlyfusioncube/typescript-best-practices` (Agent Skill)
- Install (CLI): `npx skillmds@latest add theonlyfusioncube/typescript-best-practices`
- Raw SKILL.md: https://api.skillmd.com/api/skills/theonlyfusioncube/typescript-best-practices/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: TheOnlyFusionCube (https://skillmd.com/u/theonlyfusioncube)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/theonlyfusioncube/typescript-best-practices

---

# TypeScript Best Practices

- Parse unknown external data at the boundary; keep `unknown` until validated.
- Prefer discriminated unions for mutually exclusive states and exhaustive handling for closed variants.
- Give domain meaning to primitives when accidental mixing would be costly.
- Avoid widening useful literal information and avoid `any` as an escape hatch.
- Let callers consume one coherent return shape instead of correlated optional fields.
- Use generics only when they express a real relationship between inputs and outputs.
- Keep async/error states explicit at the public boundary.
- Test behavior through exported APIs, not private helper choreography.

