dfejza.com

Why I Switched Everything to TypeScript

Why I Switched Everything to TypeScript

About two years ago, I made the call to convert all my JavaScript projects to TypeScript. Not gradually, not "for new code only" - everything. It was a lot of work, and I want to share what I actually learned, not the marketing pitch.

The Before Times

Here's code I used to write all the time:

function processUser(user) {
  return {
    name: user.name.toUpperCase(),
    email: user.email,
    joined: user.createdAt.toISOString()
  }
}
 
// Somewhere else, weeks later...
processUser({ name: "Dan", email: "dan@example.com" })
// Runtime error: Cannot read property 'toISOString' of undefined

I'd spend hours debugging things like this. The function expected createdAt, but nothing enforced it. The error shows up in production, not development.

The After

Same function in TypeScript:

interface User {
  name: string
  email: string
  createdAt: Date
}
 
function processUser(user: User) {
  return {
    name: user.name.toUpperCase(),
    email: user.email,
    joined: user.createdAt.toISOString()
  }
}
 
// Now this shows an error immediately:
processUser({ name: "Dan", email: "dan@example.com" })
// Error: Property 'createdAt' is missing in type...

The bug is caught before I even save the file. That's the pitch, and it's real.

The Honest Downsides

But here's what the TypeScript evangelists don't tell you:

Build complexity explodes. You need a compilation step now. Your CI takes longer. Hot reload gets trickier. For a quick script, the overhead feels heavy.

Library types vary wildly. Some npm packages have great types. Some have wrong types (worse than no types). Some have none at all, and you're writing @ts-ignore or as any and feeling dirty about it.

The learning curve is real. Generics, conditional types, mapped types - TypeScript's type system is its own language. I've spent hours wrestling with types that work at runtime but TypeScript refuses to understand.

You will fight the compiler. Sometimes you know something is correct, and TypeScript doesn't believe you. The escape hatches (any, type assertions) are tempting and addictive.

Was It Worth It?

Yes, but with caveats. For production applications with multiple developers, TypeScript is a clear win. For personal scripts and prototypes, I still reach for plain JavaScript sometimes.

The key insight: TypeScript doesn't eliminate bugs. It shifts when you find them - from runtime to compile time. That shift is valuable for code that matters, but it has a cost. Understand the tradeoff before you convert everything.

Two years in, I wouldn't go back. But I also wouldn't tell you it's free.