All Topics
All Topics
Technology
Technology
AI
AI
Business
Business
Entertainment
Entertainment
News
News
Programming
Programming
Science
Science
Design
Design
Environment
Environment
Finance
Finance
Crypto
Crypto
Politics
Politics
Sports
Sports
Education
Education
Gaming
Gaming
Art
Art
Music
Music
Health
Health
Security
Security
Books
Books
Food
Food
Travel
Travel
Personal
Personal
Bluesky
Twitter

Applying the Parse-Don't-Validate Principle in TypeScript: Making Illegal States Unrepresentable

By

Christian Ekrem

8d ago· 11 min readenInsight

Summary

This article explores Alexis King's "Parse, don't validate" principle and applies it to TypeScript development. The author argues that most TypeScript codebases validate data at runtime (e.g., checking `if (user.email)`) rather than parsing it into well-typed, validated structures at system boundaries. The piece examines how TypeScript's type system, while powerful, makes this functional programming principle harder to implement than in languages like Haskell or Rust. The author provides practical strategies for structuring TypeScript code to parse external data into precise types that make illegal states unrepresentable, reducing runtime checks scattered throughout the codebase.

Source

Hacker NewsApplying the Parse-Don't-Validate Principle in TypeScript: Making Illegal States Unrepresentablecekrem.github.io

Key quotes

· 3 pulled
I've been thinking about Alexis King's Parse, don't validate again. I do this quite regularly, actually, usually after staring at a TypeScript codebase that's been quietly accumulating if (user.email) checks like barnacles.
And yet most TypeScript I read — including, embarrassingly, plenty I've written — still validates instead of parsing.
The type system fights back just enough to be annoying.
Snippet from the RSS feed
Applying Alexis King's parse-don't-validate principle in TypeScript, where the type system fights back just enough to be annoying.

You might also wanna read

Comments

Sign in to join the conversation.

No comments yet. Be the first.