Why I use TypeScript
You might well see that my blog starts to center around TypeScript a lot recently. This might look like a strong deviation from what I usually blog and advocate: Performant, accessible and resilient web sites.
A lot of people ask me why I do so much with TypeScript, and why I see it as such a central piece of my day to day work. Let me explain by looking at the three encounters I had with TypeScript.
1. November 2012 - TypeScript at our local meetup #
So I dismissed TypeScript.
2. Around 2015 - Giving Angular a try #
Staying curious, I tried out the upcoming version of Angular. Don’t pin me on the date. It was a
release candidate of Angular 2. A framework that pushed TypeScript to more popularity. And the first steps
I made needed to be very strongly typed. So much annotations and decorators Angular needs to understand your
any was my best friend. But I got lost, and I gave up. I remember me saying: “TypeScript wants to know
the type of my backend results. How do I know? I haven’t even console logged it, yet!”
So… I decided to stay off of TypeScript for a while. To be fair, back then my Angular knowledge was very limited. And I think so was my willigness to change that.
3. Paternity leave 2018. Learning #
I was on paternity leave in 2018 for three months, and had the chance to learn a lot while my baby child was sleeping. I also learned new programming languages. And I thought I should give TypeScript and React a try. Just to better know what I’m talking about. And being able to judge without looking at mere aesthetics.
But then came the revelation: TypeScript analyses my code constantly. And can give great information on my code without me needing to do anything. Information my editor shows to me every time I write.
This goes well with TypeScript’s design goals
- It’s gradual. Which means you can adopt TypeScript features whenever you feel the need to.
- Control flow analysis. Everytime TypeScript can help you narrowing down possible types, it does.
- It closely tracks the ECMAScript standard. Nowadays you don’t get extra language features that haven’t reached stage 3 in ECMAScript
- Tooling, tooling, tooling. TypeScript’s not here to restrict you. TypeScript is here to provide you with tools that make you more productive.
- Every time you want to have better types, add type annotations
- Enjoy this as some extra documentation when you revisit a project
And when you work like that, it’s easy to like TypeScript. And that’s why I use it so much and why I want to write about it. It helps me, my co-workers, and my future self to actually know what I’ve been thinking. Can’t go wrong without that.