The JavaScript programming language has a lot of history, but it was created over about — yes — a week in 1995. It was first called LiveScript, but the name was changed to JavaScript to ride the bandwagon for Java, despite having nothing to do with Java. It soon became very popular, enabling the web application revolution and drawing support by practically every web browser on the planet. Today JavaScript may be the most commonly used programming language in the world.

I’m not a fan.

I’ve said for years that JavaScript is to the web browser what assembly code is to the CPU. Sure, assembly is a powerful language, just as JavaScript is, but we have higher-order languages for a reason. And given that the browser is the real operating system these days, JavaScript should — and eventually will — go the way of assembly in the minds of developers. 

I don’t deny JavaScript’s success and effectiveness. The web is built on it, and people have done amazing things with it despite its substantial shortcomings. But I just can’t bring myself to think of JavaScript as a language that we should be writing, just like only a precious few developers write assembly language today.

I prefer having a compiler write my assembly language when building Windows applications, and I prefer having compiled TypeScript write my JavaScript for me when building web applications.

TypeScript is another story. Now there is a programming language. Designed by the great Anders Hejlsberg, TypeScript has all of the benefits of JavaScript (such as they are) while adding a type system that is expressive and powerful. Frankly, I don’t understand why anyone would prefer JavaScript over TypeScript.

Why don’t you use TypeScript?

First, you can start with TypeScript at your own pace. It’s not all or nothing. All JavaScript code is TypeScript code. I (mostly) joke that I will be happy to charge a nice fee to convert all JavaScript development teams to TypeScript developers by simply changing all their *.js files to *.ts files. With that one change, they would become a TypeScript shop, and they wouldn’t have to change how they wrote code at all. They could then gradually start using TypeScript as they want. 

My lack of understanding further stems from the lame objections that developers make to using TypeScript. 

“All those types just get in the way”

Okay, sure, they may get in your way. You can maybe knock out something quickly and know everything about the code you wrote. But what about the poor sod who has to try to figure out what you were thinking when they look at your code from six months or a year ago? (Never mind that the poor sod is probably going to be you…) This is the same thing as saying, “I want to have unforeseen problems in a year when I can’t remember what all of this code is supposed to be doing.”

Typing everything allows you to clearly and succinctly declare intentions with your code as well as enforce those intentions throughout your code base. For an application with many developers, being able to clearly and definitively express what code does is a huge advantage over code that requires a fellow developer to spend cognitive energy to figure that out.

“JavaScript is great for quick prototypes”

Okay, that’s fine, but consider this: We all know that the notion of a “prototype” is kind of a joke. It’s sadly rare when a prototype is tossed aside and the “real” application is started again. Prototypes become the real application, and you are forever stuck with the bad foundational decisions you made when slapping together that prototype that you said you wouldn’t ever deploy but that you end up deploying anyway. The ability to quickly slap something together is not a virtue.

“JavaScript is good for beginners”

When I hear this one, I think, “I want budding developers to learn to code with bad habits and by not learning how a real programming language works.” 

“My fingers get tired from all that extra typing”

I mean, come on. This is the single worst excuse I’ve ever heard a developer give and I’m embarrassed for developers who seriously put this forth. You can type now when you build the system or you can do a lot more typing later when you have to maintain, redo, and fix it. Not wanting to write clear, clarifying code because it’s too much typing is absurd and lazy. All that extra keyboard work gives you a full expression of what your code is doing. You can type a bit more. Good grief.

“The TypeScript compiler only finds minor errors”

Uhm, yes. Exactly right. 

“All these types create too many errors”

Uhm, yes. Exactly right.

Okay, those last two comments were a bit flippant. But the errors are the point. The TypeScript compiler will find errors that could make it to deployment if not caught via testing. It is always better to find a problem earlier in the development cycle, and nothing is earlier than a little red squiggly showing up immediately as you type an error. 

As for “Too many errors,” well, that’s a feature. TypeScript is precise, and precision is good and desirable when coding. There’s no limit to the ways you can shoot yourself in the foot with JavaScript. I see way too many “Guess what this JavaScript code would output!” problems. If there is ambiguity and imprecision in a language, that language will result in buggy code. If you have to run code to know what its output should be, you have bad code. 

“I can use unit testing to make sure my code works properly”

This is one argument that gives me pause. I love unit testing and test-driven development, and I think we all ought to be writing our code that way, so this argument is compelling. But then I remember that you can do unit testing with TypeScript as well, so this argument kind of falls apart.

Bad programming language, bad code

When you say “I can develop quickly with JavaScript,” I hear “This project is going to be a maintenance nightmare.” When you say “I don’t like all that verbosity. JavaScript is simpler and more concise,” all I hear is “I like code to be inscrutable when I come back to it.” When you say “I just want to solve the problem and not deal with all those types,” I hear “I just want to create a huge pile of problems for myself later.” When you say “It’s hard to put types on everything,” I hear “Wah, wah, wah, wah.”

Ultimately, JavaScript was the right thing at the right time. It ended up being folded, spindled, and mutilated to serve purposes that it isn’t well suited for. That’s why TypeScript came along. TypeScript leverages the ubiquity of JavaScript while adding all the power of a modern typing system. And that is why you should be using TypeScript instead.