Driving a TypeScript Codebase to Zero Errors
Case study — taking a large React codebase from a long backlog of TypeScript errors to zero with months of small, non-functional merge requests, so the build could enforce types for good.
Context
A large React front end for an enterprise platform had moved to TypeScript incrementally, the pragmatic way most big codebases do: files first, strictness later. That left a backlog of compiler errors to clear before type checking could gate the build, and new use cases were about to land on top of it.
Problem
Until the build enforces types, they’re advice rather than a safety net: a new error is hard to spot among existing ones, and the compiler can’t catch regressions for you. At the same time, a single “fix all the types” ticket would always compete with feature work. The finish line needed reaching without pausing delivery.
What I did
- Made it a background habit, not a project. Over several months I shipped a steady stream of small, non-functional merge requests, each fixing one folder or one category of error. Each was easy to review, impossible to break much with, and merged within a day.
- Fixed causes, not symptoms. Where the same error appeared fifty times, the fix was usually one wrong type at a boundary, such as an API response or a shared helper. Typing the data layer properly (API Modelling) cleared whole swathes at once.
- No shortcuts. No blanket
any, no@ts-ignorecarpet. Where a proper signature needed more context than I had, I left an explicit, searchableunknowncast and flagged it for follow-up, rather than hiding it. - Locked in progress. Lint rules stopped new errors creeping into folders already cleaned, so the count could only go down.
- Turned enforcement on at zero. Once the count reached zero, type checking became part of the build. From then on a type error failed the pipeline.
Outcome
Zero TypeScript errors, and build-time type checking switched on for good. New code got real compiler feedback, reviewers stopped arguing about types the compiler could settle, and the remaining loose casts were a short, visible list instead of an invisible backlog.
What I’d do again
- Small and steady beats heroic. It’s progressive overload for a codebase. No big-bang rewrite, just a little more load each week, and it never blocked feature work.
- Ratchet, don’t promise. A rule that prevents regressions is worth more than a plan to fix everything.
- Make the end state enforceable. The goal wasn’t “fewer errors”, it was “the build enforces types”. That’s a finish line everyone understands.
What I’d do differently
Turn on strictness per folder from the start (with a project-references or per-directory config), so cleaned areas got enforcement immediately rather than waiting for the whole codebase to hit zero.
Related notes
Shift Left Testing · Building a Low-Code BPMN Workflow Platform · SOLID React
- #typescript
- #tech-debt
- #incremental-migration
- #code-quality
- #case-study
↩ Linked from (3)
…e to zero TypeScript errors one small merge request at a time is the most refactoring-shaped thing I've done (Driving a TypeScript Codebase to Zero Errors).
…so new use cases started from approved pieces. Hardened the codebase in parallel: TypeScript errors to zero (Driving a TypeScript Codebase to Zero Errors), a coverage drive with network-level mocks (A Testing Strategy T…
…non-functional merge requests, then turned type checking on in the build so a type error failed the pipeline (Driving a TypeScript Codebase to Zero Errors). That's when the 2020 claims came true: the types became trustwo…
↪ Links to (5)
Related by topic
- Seedcase study
Making Room for Career-Changers
Career - Seed
Prototype or Product? Scoping a Request Honestly
Career - Growingcase study
Smart TV Apps on Low-End Devices
Frontend craft - Seedcase study
Users First, Not Tools First
Career