Finally Coming Around to TypeScript

I was a Javascript Junkie for a long time before trying out Golang. Then I was a Statically Typed Junkie for a while, almost despising Javascript for the lack of safety it provides out of the box- but still acknowledging and appreciating how ridiculously fast and easy it is to build with it.

Firstly- Golang’s great. I’d use it in a heartbeat if performance/multi-threading was a bottleneck. But being a typed language isn’t special. There are plenty of statically typed languages and there are static analysis tools for just about any dynamically typed language.

Additionally, one thing that has frustrated me about Golang is the intolerance for cyclical imports, which forces the user to think very carefully about directory structure and package organization. On top of that, the brittle nature of 3rd party dependencies really settles in. Many libraries are deprecated and work awkwardly in combination with go dep.

Ultimately, the Golang ecosystem discourages using 3rd party abstractions and prefers you to build from scratch. Even folks in the community tend to respond to such inquiries with “why not just build it yourself?” It’s not entirely bad, since Golang has nice data structures like maps and dynamically sized arrays (slices), but in the end- Golang is better for building “things” and not “features”. Until I need a high-performance data-crunching service, I’ll stick to TypeScript.

The thing is- I have to thank Golang. It taught me that there really isn’t a reason for “null” most of the time- since an empty state can be represented without it. It taught me that- by having arguments that are required and typed- you can nearly reduce runtime bugs down to zero. It also made me fall in love with static typing + TDD, as I had finally reached a level of robustness that I had striven for as an engineer.

So with a recent project that’s mostly written in Node.js, but has a few Golang services- I decided to try out TypeScript as a theoretical best-of-both-worlds. And it did not disappoint.

By making both the arguments and return values explicitly typed, I’ve felt a great sense of relief knowing that the compiler will kick me in the shins whenever I inevitably use the wrong data type. The fact that TypeScript can even specify the return type of a Promise is ridiculously impressive, as you’d expect it to only support primitive or user-defined types. I’ve seen too many “of undefined” exceptions in my day to continue using vanilla JS in a professional context. TypeScript makes me sleep better at night.

Leave a Reply

Be the First to Comment!

wpDiscuz