About a year ago, I decided to try TypeScript. It seemed in demand, and I had previous positive experiences writing in typed languages. It turned out to be a good choice, but there are some things I wish someone had told me before I started.
No type checking at runtime
Upon first getting to know, I was confused. What was the point, then? Then I learned about compile-time type checking. Basically, the TypeScript compiler looks at your code before it runs in the browser or in Node, and checks to make sure everything lines up. There are other tools that do this, but with TypeScript and some of your own types to guide can become much smarter. You’ll often find errors before your code even runs!
Refactoring feels much safer
Due to the previous point, refactoring is easier. TypesScript keeps track of how code is being used and imported in multiple places. If you introduce a change in one part, it can tell you how other parts need to be changed for the code to work. As someone who easily gets distracted, this helps me remember to complete my refactoring adventures.
Prefer interfaces over types
You don’t need to use TypeScript everywhere
These are my four things I wish I’d known before I started. What’s yours? I’d love to hear your tips here →.