Pros and Cons of Typescript
Your experience might vary about the pros and cons I’ve noticed and some of issues are sort of solvable but not in the most ergonomic way.
Probably the easiest one to integrate
You will find bugs and dead code
I could bet on that. If you have a decent size codebase and even if it has tests you will find unused parameters, parameter mismatches and just dead code after adding typescript, probably once a week. Maybe even once a day. So get ready for thinking “how did this even work?.
Fewer tests are needed.
if it compiles = it works (sort of).
either write unit tests, check that dynamically or just yolo with it. So moving
to compiled language gives somehow more deterministic results.
Most of the libraries have types.
Also because of the adoption quite a few libraries while not written in typescript, ship with typescript definitions on the side. And if you create your own you always can contribute back.
Flexible type system, some smart things possible.
Type definitions can clash.
Previously mentioned points about type merging can also be an obstacle. Some libraries will include different type definitions as dependencies, which will clash. Got plenty of those while trying working with node js and react-native.
Local linking can be a pain.
Similar to that local linking will mean that you might need to manually remove a folder from node_modules to make it work or some other shenanigans.
This might not always be a case, but I’ve experienced it a few times and it was a bit of a blocker, so worth pointing out.
null | undefined | ‘’.
Not good for functional programming (missing variadic arg definition)
Because of the flexibility typescript type system provides it’s not the best
suited for functional programming. While you can achieve functional-style code,
you might need to jump through a few hoops or do some hacks here and there. Or
just sacrifice the type safety. One of the things for example to get a generic
compose functions you’d need variadic type
arguments, you could get a workaround with very smart types,
but it’s just a hack at that point.
Sometimes enforces public/private or other concepts
Every now and then decides on stupid things ¯_(ツ)_/¯
Sometimes compiler decides that you have an error in your code. Even though it’s completely valid. It might just pick a wrong type definition and that’s it. You can’t really argue with it. So you might need to do some things to get around it. Which of course can get annoying, when rather than bashing out your code, you have to bash your way through typescript.
It’s a little bit behind
At some point typescript team implemented decorators, but the spec has changed for es6 meaning they will need rewriting. After that typescript team is a little bit more defensive about the features they add. Mainly, the feature has to be in stage 3 or later to be implemented. So to get bleeding-edge features you will need some extra steps like babel and etc.
So is it worth it?
So, all in, I’d say if you can, use it.