Reading Time: 2 Minutes ReadIn my last post, I’ve introduced some frameworks like npm and bower. Now let’s have a word on TypeScript.
Too much talkThere is a lot of discussion on the Internet about the advantages and disadvantages of TypeScript, and how beneficial it is. But how does it compare to BabelJs or Traceur? Why do we need static types in a dynamic language? Is it worth the overhead? Actually, there is a better question: When is it worth the overhead? Let’s take two extremely different examples.
1. Less code fewer problemsTake a couple of hundred lines of code, probably a prototype of an idea, a demo, or something like that. There is not much complexity; a single developer can do it. In this case, BabelJs may be the better choice because it has slightly more ES6 features. You would want to implement this quickly with as little effort as possible. Writing static types on a code that will not be maintained, is not helping much. Yet the advantage of Babel is negligible. Most ES6 features are in TypeScript too, and compilation is easy to set up.
To sum it up:Static typing is effective when you do it everywhere. It has a certain overhead, but it helps more and more as the code grows.
- TypeScript has most of the ES6 features, but not as many as Babel though.
- Types provide discoverability (through IDE support).
- Autocomplete in the IDE helps to avoid typos.
- The possibility to refactor helps maintainability.
- It’s easier to understand the code by the Interfaces, rather than by reading the actual code.
- Compile time is negligible (it can be parallel and iterative).