How I’ve decided to use TypeScript
When I first discovered CoffeeScript, I just fell in love with it. I loved it. I used it in every project I was involved in. Many people doubted it. They hated extra build process. They hated the difference between the code written in CoffeeScript and the JavaScript code displayed on Chrome Inspector.
Many people still do. Many people say we should stick to plain ES6. Now that ES6 is much better than the JavaScript of the old days, I partially agree with it. I don’t need CoffeeScript anymore. But what about TypeScript?
I’ve been in a small startup last 3 years. Every moment was challenging and I had to do what it takes to survive in the business. I didn’t have extra time to follow up technical trends. Now I no longer belong to the company (It's been acquired). I think I have a little time to take a breath these days.
TypeScript is big these days. Since Angular took it as their main language, lots of people (are forced to) use it. Therefore the ecosystem of TypeScript is now rich. Many IDEs support TypeScript, many libraries are written in/for TypeScript and new framework like VueJS support TypeScript officially.
If I start a new project, should I use ES6 or TypeScript? I started to research. I googled and read lots of articles insisting we should use TypeScript. The interesting part is, so far I’ve never seen any good article saying like:
TypeScript is good not because it’s statically typed language, but it gives us the following good features when it comes to web frontend development, which are …
It turns out lots of people mainly focus on statical typing. All the articles I’ve read, however, were all about only statical typing. To sum up those articles with a little exaggeration, they're like
Statical typing is good. You should use statically typed language when developing frontend of your website. You have some options. Among them, TypeScript is the best.
Now it’s again my turn to decide whether I will bring statical typing into my project or not. It brought me to research articles about Dynamically typed language vs Statically typed language
. It’s not new and it’s a classic topic. Anyway, here’s what I’ve learned:
- Some people say we should use statically typed language because we can make fewer bugs. I don’t believe that. It sounds about right, but it’s nothing more than a myth. There’s no technical proof. Rather, there are practical researches saying the costs of using statically typed language is bigger than the benefits of fewer bugs.
- TypeScript gives us an ability to abstract things using interface.
- When I pass a configuration object in JavaScript, I have to see the implementation of the function or the document. In TypeScript, however, it’s explicit.
- Better Autocompletion
- Better Documentation
After reading articles, I’ve come up with a conclusion. It’s not “THE ANSWER”. It’s just my personal opinion including my preference. Here’s what it is:
- Classes and functions like utils, services or repositories will be written in TypeScript. They will be used in many classes and functions, so they’d better have a good guideline about parameters using TypeScript and
interface
will help me code them in a better way. - Other parts of codes like pages interacting with users will be written in ES6. I don’t think it has to be statically typed as well.
I hope this flow of my thought could help you a little on your project. I’m attaching some good articles I’ve read. Read them and make your own conclusion. It would be great if you let me know how you end up!