About typescript-best-practices
A TypeScript skill for applying type-system practices in implementation and code review. It focuses on making invalid states harder to represent and handling external data through typed boundaries.
Key features
- 01Prefer discriminated unions to boolean flags
- 02Use `satisfies` for configuration literals
- 03Parse external data into typed results
- 04Brand primitives with distinct meanings
- 05Avoid unsafe non-null assertions
- 06Use result unions for fallible functions
Use cases
- 01Review a TypeScript diff for risky types
- 02Model external JSON or CLI input safely
- 03Represent domain states without optional-field ambiguity
Install
Copy the command and run it in a terminal.
$
npx skills add https:/ / github.com/ yeachan-heo/ oh-my-claudecode --skill typescript-best-practicesAfter installing, type/typescript-best-practicesin Claude Code to confirm it loaded.
Bundled filesreferences/patterns.md
Details
From the project READMETypeScript Best Practices
The type system is the cheapest place to make illegal states unrepresentable
(principles skill, Type system discipline). Concrete forms:
- Discriminated unions over boolean flags.
type Ev = {kind:'click'; x:number} | {kind:'focus'}— not{isClick:boolean; x?:number}. Exhaustiveswitchonkindturns missing cases into compile errors. satisfiesfor configuration literals.{...} satisfies Configkeeps literal inference while checking the shape.- Parse, don't validate, at boundaries. External data (JSON, env, CLI args, API responses) passes through one parsing function returning a typed result; downstream code takes the parsed type, never
anyre-cast.unknownin, typed out. - Brand primitives that carry meaning.
type SessionId = string & {__brand:'SessionId'}when mixing twostrings is a realistic bug. - No non-null assertions on external data.
!is allowed only where a check on a previous line proves the value; at boundaries it is a runtime crash with compile-time approval. - Return types that prevent misuse. A function that can fail returns a result union, not
Tplus a thrown maybe; callers must handle both arms to compile. readonlyby default on shared shapes, mutation as an explicit opt-in.
Reviewing
When reviewing TS, the question per diff hunk is not "does it compile" but
"which illegal state did this type just permit" — flag flags-over-unions,
boundary anys, and unbranded overlapping primitives.
Rules
- Discipline applies at the boundary and the domain model; inside a single function, pragmatism wins.
- Never introduce a type abstraction with one caller and no second one
coming (
minimal-code-discipline).
Comments
Markdown supported