Why I Switched to TypeScript

January 10, 2020 (6y ago)

I resisted TypeScript for years. "It's just more boilerplate," I'd say. "JavaScript is fine for me."

I was wrong.

The Problem with JavaScript

Here's my JavaScript from 2019:

function getUser(id) {
  return fetch(`/api/users/${id}`)
    .then(res => res.json())
    .then(data => {
      return data;
    });
}

What does this function return? A user object? undefined? A promise? An error?

The answer: it's complicated. And that's the problem.

The Turning Point

I was debugging a production issue. A user's name was undefined in one specific scenario. After 6 hours of tracing through the code, I found it:

const user = getUser(id);
console.log(user.name); // undefined!

The function returned a promise, but the caller wasn't awaiting it. Classic async mistake.

TypeScript would have caught this immediately:

interface User {
  id: number;
  name: string;
  email: string;
}

async function getUser(id: number): Promise<User> {
  const res = await fetch(`/api/users/${id}`);
  return res.json();
}

// Now this is an error:
const user = getUser(1);
console.log(user.name); // Error: Property 'name' does not exist on type 'Promise<User>'

The error happens at compile time, not in production.

What TypeScript Actually Gives You

1. Documentation That Doesn't Lie

interface Project {
  id: string;
  name: string;
  status: 'active' | 'completed' | 'archived';
  team: Team[];
  createdAt: Date;
}

I know exactly what a Project looks like. No guessing. No reading 500 lines of implementation.

2. Refactoring Without Fear

Rename a property? Move a file? Change a function signature?

In JavaScript, you break things and find out later. In TypeScript, you break things and know immediately.

3. Better IDE Support

Auto-complete that actually works. Inline type hints. Go-to-definition for variables. These aren't gimmicks — they make coding faster.

The "Any" Escape Hatch

"But you can just use any!"

Yes. And I did, initially. The escape hatch exists.

But here's the thing: the more you type, the less you need any. The discipline of defining types — even loosely at first — pays off.

My TypeScript Journey

  • 2019: Added // @ts-check to JavaScript files
  • 2020: Full TypeScript migration on new projects
  • 2021: Retroactively typing old projects
  • 2022: Can't imagine starting anything without it

The Verdict

TypeScript isn't about being perfect. It's about being clear. About catching mistakes before they cost you. About having a contract between your code and your future self.

I don't write JavaScript anymore. Not because it's bad — but because TypeScript is better.

Next: The React Hooks Mental Model