lootlog/monorepo / .agents/skills/typescript-best-practices
typescript-best-practices
VerifiedApply this repository's TypeScript modeling and implementation discipline when reading, writing, reviewing, or refactoring .ts and .tsx files, especially public contracts, domain state, external-data boundaries, and shared packages.
TypeScript best practices
Follow AGENTS.md and the repository lint configuration first.
Model the data
- Use discriminated unions when code has real variants. Avoid bags of optional fields that permit invalid combinations.
- Keep the simplest total type. Introduce branded primitives or non-empty tuples only when they prevent a demonstrated class of mistakes.
- Derive types from authoritative schemas and existing values with
typeof,Pick,Omit,Parameters,ReturnType, or generated contracts. - Parse external data at HTTP, queue, storage, configuration, and browser boundaries. Keep it
unknownuntil validation succeeds. - Prefer exhaustive switches. Make unhandled variants fail type checking.
Write honest TypeScript
- Avoid
any, non-null assertions, and unchecked casts. When a library boundary requires a cast, keep it local and prove the invariant in code structure or a test. - Prefer
satisfieswhen validating an object without widening its literals. - Use
===,??, and optional chaining as specified by the project. - Use one import per module and inline
typespecifiers for type-only names. - Avoid nested ternaries. Use early returns or explicit branches.
- Use descriptive names and prefix genuinely unused variables with
_.
React
- Let React Compiler handle memoization. Add
memo,useMemo, oruseCallbackonly for a measured integration constraint. - Keep one component per file.
- Route all static user-facing text through i18n.
Verify
Test behavior through public seams. Prefer real framework primitives over mocks, and run the narrowest relevant typecheck, lint, and test tasks.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementation | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirements | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallback | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |