# Typescript Best Practices

> Design or review TypeScript with constructive domain types, boundary schemas, exhaustive variants, and tests that exercise runtime uncertainty.

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

---


# Apply TypeScript type discipline

Treat the request text that activated this skill as the TypeScript change or review target.

When React props admit states absent from live callers, apply
[`narrow-react-prop-types`](../narrow-react-prop-types/SKILL.md) to that portion and reuse its
call-site inventory. Keep broader runtime schema and domain work in this method.

Inspect the repository's compiler settings, runtime schema library, lint rules, and local patterns
before proposing a new abstraction. Model state with discriminated unions and semantic primitives
when they remove invalid combinations. Accept external data as `unknown`, validate it once at the
boundary with the existing schema mechanism, and derive types from the authoritative schema where
possible.

Avoid `any`, unchecked assertions, broad index signatures, optional-field state machines, and guards
that only repeat an interface. Exhaust variants so a new case breaks every affected caller. Keep
generics narrow and inferable; prefer a direct concrete type over type-level cleverness.

Test valid and invalid runtime inputs, narrowing behavior, each state transition, and serialization
boundaries. Run the repository's typecheck, focused tests, and lint. Report strengthened invariants,
remaining assertions with reasons, and any runtime behavior not covered by types.

