Why I Write Every Project in TypeScript

May 11, 2025#typescript#javascript#dx

JS vs TS

The bug that converted me

A feed page rendered fine locally and broke in production: post.author.name — where author was sometimes undefined. JavaScript said "cannot read properties of undefined", the user saw a white screen, and the stack trace pointed at a file I had not touched in a month. TypeScript would have refused to compile the very first version of that code.

What the migration cost

Three evenings. Not because it was hard — because it was mechanical, and mechanical work is where you discover how badly you needed types. JSDoc hints, any patches, and one marathon session fixing the places that had been wrong for years.

What you actually get

type Post = {
  id: string;
  author?: User; // nullable, on purpose
  body: string;
};

function renderAuthor(post: Post) {
  return post.author?.name ?? 'deleted user'; // compiler checks the path
}

The type is documentation that runs. Refactoring becomes a search-and-replace the compiler audits for you. And when a colleague opens the repo, the shape of the data is the first thing they see — not the fifth thing they discover by reading the docs.

The best time to add types is the first commit. The second best time is right now.

***