How I feel about Web Development after learning TypeScript
That isn’t to say that it is the perfect tool for everything, but it’s served me well over the years. I’ve stoically acknowledged the flaws levelled at the web’s front of house workhorse, including Gary Bernhardt’s tongue-in-cheek “Wat?” lightning talk that still has be chuckling just thinking about it. If you’ve never seen it before, stop reading now and go watch it. You can thank me later.
So why am I now threatening to leave and never return? The answer is simple. Typescript.
What is Typescript?
But as I said, I’ve never heard anyone who adopted Typescript and regretted it. The benefits far outweigh the difficulties, especially in an age of the Angular CLI or Create React App — both of which allow you to get started with a new Typescript enabled project in minutes.
I assume you know what those benefits are, but in case you don’t, allow me to summarise:
- Typescript’s compilation step means you can catch problems early instead of waiting for runtime failures.
- Your IDE can now prompt you even earlier that the compilation step. Imagine your IDE telling you when you refer to a variable that doesn’t exist or you call a function with the wrong arguments! Truly revolutionary! (I’m being facetious, of course, since “real” programming languages have enjoyed this for years)
This is what I mean. Is “error” a boolean? It sure looks that way when I see line 2, but what about the million lines of code between that and the end of “doTheThing”? It could be a string, an object, or who knows what.
And that’s the beauty of TypeScript. It doesn’t force you to be a good developer. But it gives you the tools to do so.
Are there drawbacks? Of course there are.
- Since you have to compile your code, every update and every test run will take just a little bit longer. But we’re talking seconds. The amount of time I save by using Typescript far outweighs the time I spend compiling it.
- The complexity of building the project can be a real pain at times. This one is real — if you’re not familiar with your build tools, setting up a new project can be a frustrating experience. My advice in the short term is to find a starter project to get you going. Long term? Invest time in learning the tools — tsc, Babel, WebPack and all that good stuff.
It kinda feels like my argument is a little one sided though — I’m not devoting so much effort to the drawbacks as to the advantages. I guess that’s for the same reason I wouldn’t devote much time to the advantages of eating McDonald’s for every meal — there are limited advantages to doing that (not having to cook ever again… I guess that’s it).
And that’s why I’ll never go back.