type-driven-design
Installation
SKILL.md
Type-Driven Design
"Make illegal states unrepresentable." — Yaron Minsky, Jane Street
Use the type system as the first line of defense. If the compiler rejects invalid states, they cannot occur at runtime. Shift validation from a runtime cost scattered across the codebase to a one-time compile-time guarantee at the boundary.
Core Principles
1. Parse, Don't Validate (Alexis King)
The key distinction:
- Validate: check if data is valid, then pass the raw value around — you must check again everywhere
- Parse: transform raw input into a type that proves the check passed — downstream code needs no checks at all
// Validate (bad): string passes the check but stays a string
validateEmail(s string) bool