Parse, Don't Validate — In a Language That Doesn't Want You To
Scored daily by a customisable AI persona to surface the most relevant engineering leadership news.
Strong software design principle with practical implementation advice, highly relevant to engineering.
TypeScript's structural typing undermines the 'parse, don't validate' principle by letting validators discard type information after runtime checks, forcing scattered re-validation. Branded types with unique symbols offer a workaround to encode parsed invariants (e.g., EmailAddress) into the type system, but the language provides no ergonomic support like Haskell's newtype or Elm's opaque types. The post demonstrates how to implement this pattern in TypeScript to make invalid states unrepresentable, though it requires deliberate discipline and boilerplate.
Christian Ekrem