Featured Article
KryttrAugust 26, 20262 min read

The Bugs TypeScript Would Have Caught Last Tuesday

Every untyped JavaScript codebase eventually ships the same category of bug: a value that was undefined in a place the code assumed it couldn't be.

TypeScriptEngineeringCode Quality
The Bugs TypeScript Would Have Caught Last Tuesday

The bug report that's always the same shape

“It works most of the time, but sometimes it crashes” is one of the most common bug reports in a growing JavaScript codebase, and it's almost always the same root cause wearing a different disguise: a function assumed an object had a field that, under some condition nobody tested, it didn't. An API response changed shape slightly. A prop was optional somewhere and required somewhere else. None of these are exotic bugs — they're exactly the class of error a type system exists to catch before the code ships.

Why teams delay adopting it

The usual objection is migration cost, and it's a fair one for a codebase with real production traffic. Nobody wants to pause feature work for a rewrite. The good news is that a full rewrite is not actually how a realistic TypeScript migration goes — incremental adoption lets a codebase convert file by file, with an explicit, visible escape hatch for the parts not converted yet, rather than an all-or-nothing cutover.

What incremental adoption actually looks like

  • Turn on TypeScript checking against existing JS files first, catching type errors without converting anything yet

  • Convert new files and heavily-modified files as you touch them, rather than scheduling a dedicated migration sprint

  • Type the boundaries first — API responses, form inputs, database models — since that's where the highest-value, highest-frequency bugs live

  • Turn on strict mode last, once the bulk of the codebase is typed, rather than fighting it from day one

The part beyond bug prevention

The less-discussed benefit is onboarding. A typed codebase tells a new engineer what a function expects and returns without needing to trace through five other files or ask around. When we inherit an existing JavaScript codebase from a client, an incremental TypeScript migration is often one of the first things we propose — not because it's exciting work, but because it measurably reduces the number of “how does this even work” questions in the following months.

Share Article

About the Author

Kryttr is a passionate developer and writer, sharing insights about web development and digital innovation.

Learn More

Related Articles

Continue exploring our latest insights and expert perspectives

View All Articles