TypeScript: pros and cons
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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
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.