typescript-best-practices
Installation
SKILL.md
TypeScript Best Practices
Goal
Make code safer and easier to change. Use TypeScript to model real constraints without adding noise.
Rules
- Prefer
unknownoverany. - Let inference work for local values.
- Add explicit types at boundaries: exports, API input/output, public functions.
- Enable strict compiler options when project allows.
- Use discriminated unions for state variants.
- Narrow unknown data before use.
- Prefer
interfacefor object shapes. - Prefer
typefor unions and utility types. - Avoid type assertions unless crossing a known boundary.
- Keep runtime validation near external input.