Trung Nguyen
Migrating a REST API to TypeScript hero

Backend Developer — 2025

Migrating a REST API to TypeScript

Migrated a legacy Express API serving 50k monthly requests to TypeScript — eliminating a class of runtime errors and cutting bug reports from the frontend team by 60%.

Role

Backend Developer

Timeline

3 months

Tools

Node.js, TypeScript, Express, PostgreSQL

Case study detail
Detail left Detail right

The problem

A Node.js/Express API that had grown organically over three years had no type safety. Runtime errors were making it to production regularly. The frontend team spent significant time debugging issues that turned out to be shape mismatches between what the API promised and what it actually returned.

The codebase had 47 endpoints, no tests, and no documentation.

Starting with the edges

I resisted the temptation to rewrite. Instead, I introduced TypeScript incrementally — starting at the boundary layer: request validation with Zod and typed response schemas. This caught the most common class of errors without requiring a full migration upfront.

Once the boundary was typed, propagating types inward was straightforward. The compiler became the reviewer.

Migration strategy

The migration ran alongside normal product development. Each endpoint was migrated when it was touched for a bug fix or feature, rather than in a dedicated rewrite sprint. This kept the team unblocked and reduced the risk of a big-bang migration.

I also introduced a lightweight test suite — not comprehensive coverage, but enough to pin the behaviour of the 12 highest-traffic endpoints before migration.

The outcome

Full TypeScript coverage reached in 11 weeks. Runtime errors from type mismatches dropped to near zero in production. Bug reports from the frontend team fell 60% over the following two months.

The Zod validation layer also became the source of truth for API documentation — auto-generated and always in sync.

Discussion

Powered by GitHub Issues. Join the conversation ↗

johndoe 2 days ago
Really interesting approach. How did you decide on this direction over the alternatives?
trungnguyen 1 day ago Author
The main constraint was time and existing systems. The alternative would've been cleaner but needed a full rebuild — not an option at the time.
minh.dev 18 hours ago
The before/after breakdown is exactly what I needed. Bookmarking this one.

To leave a comment, you need a GitHub account.

Comment on GitHub

More Case Studies

Building a Component Library from Scratch

Building a Realtime Analytics Dashboard

Rebuilding the Onboarding Flow