typescript-best-practices
/typescript-best-practices
TypeScript best practices. Use when reading or editing any .ts or .tsx file.
- Author
- sma1lboy ↗
- Repository
- rove ↗
- Licence
- MIT
- Last repository change
- 27.10.2026
Assessment and security
- Files in this package
- 2
- Scripts
- 0
- HTML comments
- 0
- URLs in SKILL.md
- 0
No signals detected. Repository changed on 27.10.2026, without references to retired models or APIs.
MIT, open: use and modify while retaining author attribution.
What it does and when to use it
TypeScript best practices. Use when reading or editing any .ts or .tsx file.
Original author description
TypeScript best practices. Use when reading or editing any .ts or .tsx file.
How it works
SKILL.md has no level-two headings · 25 lines, 385 words
SKILL.md preview
---
name: typescript-best-practices
description: TypeScript best practices. Use when reading or editing any .ts or .tsx file.
---
# TypeScript best practices
Apply the **type-system-discipline** principle skill first; this skill grounds it in TypeScript syntax.
| Rule | Summary |
|------|---------|
| Discriminated unions | Model variants with a `kind` literal discriminant so impossible states can't be represented. No optional-field bags. |
| Branded types | Brand primitives with `& { readonly __brand: "X" }` so they can't be mixed up. Validate once at creation. |
| Constructive modeling | Build the shape so the illegal value can't be constructed. `[T, ...T[]]` for non-empty, `[T, T][]` for even length, `start` plus `duration` for a range. Not a runtime guard, not a wish for refinement types. |
| Simplest total type | Keep `T[]` while every operation on it stays total. Strengthen to `NonEmpty<T>` only where the loose type forces `!`, a cast, or a "should never happen" throw. |
| `unknown` over `any` | External data is `unknown`. `any` disables type checking everywhere it touches. |
| No `as` casts | Every `as` is a runtime crash waiting. Cast only after validation. |
| Narrowing hierarchy | Discriminant switch > `in` operator > `typeof`/`instanceof` > user-defined type guard > `as`. |
| Type guards | Must verify the claim. A lying guard is worse than `as` because the bug hides behind a name that says it's safe. Name them `isX` or `hasX`. |
| Exhaustiveness | Inline `const _exhaustive: never = x;` in default arms so the compiler errors when a new variant is added. |
| `satisfies` over `as` | Validates the value without widening literal types. |
| Boundary validation | Parse where data crosses in, into a named domain type. `Record<string, unknown>` (however spelled) stops at that parse. Trust types inside. See the **boundary-discipline** principle skill. |
| Schema-derived types | Reach for `Pick`/`Omit`/`Parameters`/`ReturnType`/`Awaited`/`typeof` before declaring a new interface. |
| 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 `console.log` in shipped code. |
Examples: `references/patterns.md`.
Files in this package (2)
- SKILL.md 2 KB
- references/patterns.md 8 KB
Versions
| Repository | Score | Licence |
|---|---|---|
| This page · sma1lboy/rove | 87 | MIT |
| seaworld008/commonly-used-high-value-skills | 100 | MIT |
| HoangNguyen0403/agent-skills-standard | 100 | MIT |
| overextended/skills | 100 | GPL-3.0 |
| alleneubank/claude-code | 100 | Apache-2.0 |
| VdustR/vp-claude-code-marketplace | 100 | MIT |
| fcakyon/claude-codex-settings | 91 | Apache-2.0 |
| workerstack/clients | 91 | MIT |
| itsvedantkumar/vstack | 91 | MIT |
Identical content appears in 5 other GitHub folders. We show one copy with the highest score.
Database snapshot: 13.11.2026 · package version 4cb2ee87c1ca (SHA-256 digest of the entire package)
Downloads in the last 30 days: 2 · ranking
Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.
Similar skills
- 87mroowa-typescript-best-practices
TypeScript best practices. Use when reading or editing any .ts or .tsx file. - 100react-best-practices
Use when reading or writing React components (.tsx, .jsx files with React imports). - 100typescript
This skill should be used when writing or reviewing TypeScript or TSX code, or when the project uses "TypeScript", "React", "tsx", "SWR", "Vite", "Next.js", or TypeScript type patterns. Provides TypeScript coding conventions, React patterns, and best practices. Project-specific… - 100python-best-practices
Use when reading or writing Python files (.py, pyproject.toml, requirements.txt). - 91typescript-forms
Katara's TypeScript forms, practiced until every move is exact. Use for typescript-best-practices, /typescript-best-practices, "TypeScript best practices", and whenever reading or editing any .ts or .tsx file. Discriminated unions, branded types, constructive modeling, unknown… - 100trove-typescript
TypeScript type-system discipline for any .ts/.tsx file: make illegal states unrepresentable, validate at boundaries, avoid as/any. Use when reading or editing TypeScript that isn't covered by a framework-specific skill. Defers to trove-react / trove-react-best-practices on .tsx component work.