JavaScript to TypeScript

February 2025. Project in JavaScript. Works. But every day I catch bugs that TypeScript would have caught.

// Somewhere in the code
user.nmae  // typo, find out at runtime

Decided to migrate. Scary - lots of files, rewrite everything.

How I did it

Didn't rewrite everything at once. tsconfig.json with allowJs: true. New files - .ts. Old ones - gradually.

Started with types for basic entities: User, Product, Order. Then controllers. Then services.

In a week - 80% of files. The rest as I go.

What changed

IDE suggests. Errors visible before running. Refactoring is safe - rename a field, see all places where it broke.

// Now like this
interface User {
  id: number
  name: string  // can't make a typo
  email: string
}

How long it took

A week for the main migration. Another month catching any and replacing with proper types.

Worth it. JavaScript: find out about error when it crashes. TypeScript: find out before running.

← Back to blog