Cassio Zen

March 4, 2021

Why I use TypeScript

(Adapted from this original article)

When TypeScript got released I was skeptical. I saw friends using it - They did backend, mostly Java, and relied on things like “abstract classes” and “interface hierarchies” and “factories” and… yuck!

That’s not JavaScript. And I like JavaScript! So I dismissed TypeScript.

Sometime later I thought I should give TypeScript and React a try, to better know what I’m talking about and judge without looking at mere aesthetics.

When working with TypeScript, I found out that I can just write JavaScript like usual. No extra annotations. No-fuss.

But then came the revelation: TypeScript analyses my code constantly. And give great information on my code without me needing to do anything. Information my editor shows to me every time I write.

The truth is, if you are using VSCode, you are using TypeScript without knowing.

The TypeScript language server runs in the background, analyzing your code and reporting back. This gives a better development experience without much effort.

TypeScript becomes an extra brain that knows my code better than I do.

(And where it doesn’t, I can give TypeScript a little bit of extra type information to make it understand.)

This goes well with TypeScript’s design goals

- It’s gradual. This means you can adopt TypeScript features whenever you feel the need to.
- Extensive type inference. TypeScript wants to know your JavaScript
- Control flow analysis. Every time TypeScript can help you narrowing down possible types, it does.
- Tooling, tooling, tooling. TypeScript’s not here to restrict you. TypeScript is here to provide you with tools that make you more productive.

So TypeScript… is JavaScript. JavaScript with benefits. And I like Javascript! And I like benefits.

My approach:

- Write JavaScript. Be happy when something isn’t any
- Every time you want to have better types, add type annotations
- Enjoy this as some extra documentation when you revisit a project
- Stay away from any extra language stuff that mixes type annotations with stage 3 JavaScript. They are a relict of old times.

And when you work like that, it’s easy to like TypeScript. It helps me, my co-workers, and my future self to actually know what I’ve been thinking. Can’t go wrong without that.