I’ll Never Go Back to JavaScript

How I feel about Web Development after learning TypeScript

Jamie Morris
Nov 24 · 6 min read

JavaScript may be the defacto language of the modern web, but it has long been my language of choice for scripting, too. Python is fun to code in, but if I have something to automate, I reach for node. My server side language of choice used to be C#, but nowadays it feels clumsy, albeit powerful. Node, which I once naïvely described as a “flash in the pan”, meets the needs of everything I write. I can even write Android and iOS apps in JavaScript in a number of different ways.

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.

That lightning talk has been part of the recommended reading list (viewing list? consuming list?) that I give to would-be front end developers, alongside Jonathan Creamer’s “JavaScript Architecture for the 23rd Century”. While some of the content in the above article seems redundant since the advent of ES6, it goes a long way to explaining the things about JavaScript that require a mindset shift from “normal programming languages” (if there is such a thing). That article alone is a large part of the reason that I began my own JavaScript Odyssey 5 years ago.

So why am I now threatening to leave and never return? The answer is simple. Typescript.

What is Typescript?

I assume you’ve heard of Typescript, but if not, let me try and summarize: Typescript is strongly typed Javascript. It adds the features you would expect of a strongly typed language, and requires a compilation step (technically it’s “transpilation”) to turn the Typescript into JavaScript. This is because browsers do not understand Typescript. Technically speaking, Typescript does not add any new runtime features — it instead adds features for the developer.

I’ve heard some people describe Typescript as a love it or hate it language, but I’ve yet to speak to anyone who has tried it and hated it. I’ve spoken to plenty of people who were hesitant to try it — in about mid 2016 I was one of those people. But the worst criticism I’ve heard levelled at Typescript by my peers is that it’s an extra set of tools to learn. Not just the language, but the build process, too. However most modern web apps have at least one link in their build chain reserved for JavaScript in the form of Babel — the tool that allows newer JavaScript to run on older browsers. Adding TypeScript into that pipeline shouldn’t be rocket science, especially since Babel has supported Typescript compilation since v7.

It shouldn’t be rocket science, but it sometimes feels that way, which is one of the reasons that newcomers to Typescript sometimes flounder and run back to the welcoming arms of JavaScript, which runs right there in the browser.

The Benefits

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)
  • When new features are proposed in ECMAScript (the standard that drives JavaScript), TypeScript is able to adopt them early, allowing you to stay on the cutting edge.

But really, the main benefit is that Typescript makes your code self describing in a way that JavaScript can’t. When I’m the lone developer on a project, JavaScript isn’t so bad because I can keep everything in my head and I have a perfect memory, right? Wrong. Even as a sole developer I am prone to bouts of amnesia when it comes to code I’ve written. Nowadays, when I write plain JavaScript, I hate having to go and read a function definition to figure out how to use it. I don’t know what it returns (if anything) or what kind of arguments it accepts. I might know the number of arguments and their names, but that’s not always enough:

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.

You might argue that this flexibility is an asset. It can be, but more often it’s a trap, luring you into easy ways that will cause many micro-frustrations among you and your peers. Ever been in the middle of someone else’s code and felt like you were in a labyrinth? That’s what your code looks like to someone else. You can write “good” code in JavaScript, but very little about the language encourages you to do so.

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.

The Drawbacks

Are there drawbacks? Of course there are.

  • More typing, in both senses of the word. You’ll wear your keyboard out faster (which may be a concern for those of you with butterfly keyboards). It’s not such a big deal, but some JavaScript developers hate having to type out types with every new function or variable. You don’t have to do that, but if you’re not using types, why are you using Typescript?
  • 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).

The Stats

As always, StackOverflow provides the gauge for how right or wrong I am. At first glance, it looks like I’m way off the mark. According to StackOverflow’s 2019 Developer Survey, JavaScript is, for the seventh year in a row, the most talked about language on StackOverflow, with 67.8% of respondents using it. Typescript is languishing in 10th place on 21.2%.

In 2018, however, Typescript was at 17.4%, and only 9.5% the year before. In 2016, only 0.47% of respondents used Typescript. In that respect, Typescript has had a pretty phenomenal rise, largely thanks to the Angular framework, which abandoned JavaScript support early on.

When you look at the “Most Loved” languages, it’s even better for Typescript, which sits in 3rd place (73.1%) behind Rust and Python. JavaScript is on 11th (66.8%).

The Future

I don’t think Typescript is going to replace JavaScript any time soon — understanding the latter is crucial to making the former work. And we’re not about to see Typescript running natively in any browser. It is a preprocessor, like CoffeeScript was before it. The difference between Typescript and Coffescript is that the latter was a fundamental change to the language it was built upon. Typescript is a natural evolution. Not only does this make it easier to learn, but it makes converting a JavaScript project to Typescript a much more incremental process. Start by renaming *.js to *.ts. Now you’ve got a Typescript project! You can then start adopting the language features one step at a time. I can’t promise that it will be easy, but it will tell you things about your code that JavaScript never could. The Typescript compiler will be waiting when you embark on your next project

And that’s why I’ll never go back.

JavaScript in Plain English

Learn the web's most important programming language.

Jamie Morris

Written by

I used to be a full stack developer, but nowadays most people only want me for my <body>, so I try to be a UI expert. I must try harder.

JavaScript in Plain English

Learn the web's most important programming language.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade