TypeScript: pros and cons

Aux
3 min readOct 19, 2016

--

I played with TypeScript for a couple of years. From time to time. But I only started using it in my day to day work six months ago. TypeScript 2.0 was released recently and I decided to summarise my experience with this language and its tooling.

Pros

  1. Static typing. It helps and helps a lot. I have more than 5 years of PHP experience and about the same with Java. Statically typed languages do minimise the amount of mistakes you make and improve code analysis so that all your tools like IDE can provide you hints, assistance and proper refactoring. Yes, it forces you to type a bit more, and yes, types are optional in TS so you can easily shoot yourself in the foot, but I still find them very beneficial. Especially for medium to large teams working on large projects which should be supported for many years.
  2. Syntax sugar. I like sugar! And TS has plenty of it. Classes, interfaces, fat arrow functions, etc. The best part of TS syntax sugar is that there is no magic behind it and it feels as a very natural extension to JavaScript language. And I think this is one of the reasons why many of TS features are getting adopted in ECMA specifications in one way or another.
  3. JavaScript super-set. In short that means that all of your existing JS code is already a TS code. And that makes learning TypeScript a very easy task. Its learning curve is very simple, you start with renaming your .js files into .ts files and creating a very simple tsconfig.json file. Then you start learning and using new features one by one. A few months or even weeks later you will notice that you are pretty familiar with the most useful TypeScript features and the language has become your second nature.
  4. Future today. As mentioned before, many of TS features became a part ECMA specification. And thanks to compiling (transpiling) you don’t need to wait for browser adoption. And you can also take a peek at what’s coming next and get prepared today.
  5. Plenty of tools! Many languages and frameworks suffer due to thelack of good tools. Thankfully Microsoft (the guys behind TypeScript) did an awesome job of creating a very good compiler itself and a language service, which provides code analysis and auto-completion for IDEs and text editors. There are also plenty of tools created by TS community like tslint, typings, build system plugins and so on.
  6. Great community and documentation. Language documentation covers all you need to know about the language and since more and more developers use TS, community is very big and supportive these days.

Cons

  1. Language configuration. I’m strongly against any language options which modify the way source code is interpreted. The amount of such options in TS is very small, most of configuration is about how to generate output, but Microsoft keeps adding language modifiers over time. I remember PHP and its bazillion options which can render your application unusable very easily and I don’t want to experience that with TypeScript. Well, at least tsconfig.json is a part of your project and not some global .ini file affecting all of the projects running on your machine.
  2. Package manager. There is none. And everyone is using npm and JS libraries. I think TS would greatly benefit from having a separate package library which would be filled with code which uses all the benefits of the language.

Conclusion

I started to really enjoy writing TS code instead of good old JS. Back in the days TypeScript had more issues, but Microsoft resolved most of them. And what is left there does not really affect my work. Two downsides I found so far are like small niggles, not really downsides.

Will TypeScript make your life better? Well, I don’t know. It depends on many factors. Is your team ready for changes? Do you have loads of legacy code? Will you be able to use new language features to your benefit? There are plenty of questions you need to answer. But I’d suggest that you should at least try TypeScript for your small home project to understand if it will be beneficial to you and your team. My team is happy with this language and so am I.

--

--