Loading...
Loading...
TypeScript best practices. Use when reading or editing any .ts or .tsx file.
npx skill4agent add hachej/boring-stack typescript-best-practices| Rule | Summary |
|---|---|
| Discriminated unions | Model variants with a |
| Branded types | Brand primitives with |
| Constructive modeling | Build the shape so the illegal value can't be constructed. |
| Simplest total type | Keep |
| External data is |
| Schemas before guards | Before hand-writing a property-by-property type guard, use the repository's runtime schema library and infer the type from the schema, such as |
No | Every |
| Narrowing hierarchy | Discriminant switch > |
| Type guards | Must verify the claim. A lying guard is worse than |
| Exhaustiveness | Inline |
| Validates the value without widening literal types. |
| Boundary validation | Parse where data crosses in, into a named domain type. |
| Schema-derived types | Reach for |
| Object args | Pass objects, not positional, so argument order is self-documenting. Skip on hot paths (per-frame render, tokenizers, parsers). |
| Real tests | Don't mock what you can run. Prefer the framework's real test primitives with leak/disposable checks, and verify UI in a running build. Mock only what you can't run locally. |
| Structured telemetry | Prefer structured logger diagnostics with enough context to debug from an id. No |
references/patterns.md