Use cases for Typescript
- Code size: When the source code is huge and more than one person works on the project, a type system can help avoid the obvious errors. When someone can change code that potentially can another one’s code, it’s generally good to have some sort of safety mechanism. The compiler of Typed languages reveals mistakes with the obvious syntax errors (but can’t eliminate the need for debugging of course). If the source code is not huge, it probably doesn’t make sense to make it longer by adding type annotations. I have converted 180+ files to JS to TS and in most cases it added roughly 30% to the code size.
When not to use Typescript?
- Extra compilation tax: There are no plans to support Typescript natively for the browsers. This means you will always have to compile your code before feeding it to the browser. On the other hand when ECMA 6 is supported by most browsers , that extra compilation is not necessary which makes the code load. You just modify the file and refresh the browser. That’s all — no “watching” or “compiling on demand” or build system.
- Weird debugging edge cases: Sourcemaps make it easier to debug Typescript, but the status quo is not perfect and there are really annoying/confusing edge cases that the browser things you are running a certain line of code but you are not. Also there are some problems debugging the `this` keyword and whatever is attached to it occasionally.