Parse, Don't Validate — In a Language That Doesn't Want You To
Applying Alexis King's 'parse, don't validate' principle in TypeScript using branded types and discriminated unions. The core idea: validators discard proof the moment they finish, while parsers encode correctness into the type system itself. The post walks through hand-rolling branded types with unique symbols, building Result-style discriminated unions, and structuring domain types (UnvalidatedUser vs ValidUser) to make illegal states unrepresentable. It also covers TypeScript's friction points — structural typing, the necessary 'as' cast inside parsers, lack of a native match expression — and how Zod automates the pattern without changing the underlying discipline required.