Catalog
Yeachan-Heo/typescript-best-practices

Yeachan-Heo

typescript-best-practices

TypeScript grounding for type-system discipline: discriminated unions over flags, satisfies, parse-don't-validate at boundaries, branded primitives, no non-null assertions on external data.

v1.0LATEST
NewUpdated Nov 8, 2026

TypeScript 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}. Exhaustive switch on kind turns missing cases into compile errors.
  • satisfies for configuration literals. {...} satisfies Config keeps 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 any re-cast. unknown in, typed out.
  • Brand primitives that carry meaning. type SessionId = string & {__brand:'SessionId'} when mixing two strings 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 T plus a thrown maybe; callers must handle both arms to compile.
  • readonly by 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).
Files2
2 files · 3.0 KB

Select a file to preview

Overall Score

87/100

Grade

A

Excellent

Grades are signals, not a certification. Always review a skill yourself before use.

Safety

95

Quality

88

Clarity

85

Completeness

82

Summary

A TypeScript discipline skill that guides developers on type-system best practices: discriminated unions, `satisfies`, parse-don't-validate at boundaries, branded primitives, and strict null handling. The skill provides concrete code examples and review guidance to make illegal states unrepresentable and prevent runtime crashes through compile-time guarantees.

Detected Capabilities

code analysisTypeScript pattern recognitionreview guidance documentation

Trigger Keywords

Phrases that agents use to match this skill to user intent.

type safety reviewdiscriminated unionsbranded primitivesparse-don't-validatenon-null assertionstypescript patternsboundary validation

Referenced Domains

External domains referenced in skill content, detected by static analysis.

github.com

Use Cases

  • Review TypeScript code for type-safety violations
  • Refactor boolean flags to discriminated unions
  • Apply branded types to prevent primitive mixing
  • Implement parse-don't-validate at API boundaries
  • Audit for unsafe non-null assertions
  • Write type-safe configuration handling

Quality Notes

  • Excellent concrete code examples in patterns.md covering all key rules
  • Clear principle-to-practice mapping (discriminated unions, branded types, parse-don't-validate)
  • Well-defined scope focused on type discipline at boundaries and domain models
  • Strong pedagogical structure with anti-patterns and correct patterns side-by-side
  • Minor: Skill body references 'principles' and 'minimal-code-discipline' without defining them — assumes prior context
  • References external pstack project for historical context but is self-contained
  • Pragmatic guidance ('inside a single function, pragmatism wins') prevents over-engineering
Model: claude-haiku-4-5-20251001Analyzed: Nov 8, 2026

Reviews

Add this skill to your library to leave a review.

No reviews yet

Be the first to share your experience.

Use Yeachan-Heo/typescript-best-practices in your dev environment

Command Palette

Search for a command to run...