How to Break TypeScript (and How to Put it Back Together)
summary
Demonstrates a concrete TypeScript program where a variable of type RegisteredUser|AnonymousUser is narrowed by an instanceof check via flow-sensitive type refinement, then reassigned to the other variant and later refactored into a helper so the compiler loses the refinement; the type checker accepts the first form but rejects the refactored one even though runtime behavior is identical. Shows proposed fixes — require new variables (C# style), add full Hoare logic (pre/postconditions), or enforce immutability — and cites Anders Hejlsberg warning that deeper analysis is costly and brittle.
AI-written summary · about
chapters (6)
- 0:00Introduction to TypeScript
- 1:45Analyzing type refinement
- 5:25Language design trade-offs
- 6:46Historical context
- 6:58Software engineering lessons
- 11:54Closing remarks
related talks
01h 01mDeconstructing TypeScript’s Type System
22mThink you know TypeScript? Think again.
01h 05mBusy TypeScript Developer’s Guide to Advanced TypeScript
51mTypeScript - Beyond the Basics
34mNot Your Uncle’s Clean Code (TypeScript Edition)
21mLearning to Love Type Systems
24mTypeScript for JavaScripties
30mSwipe Left, Uncaught TypeError Learning to Love Type Systems
