What’s so great about TypeScript?

Claudynn Lee
3 min readOct 6, 2021

TypeScript was developed by Microsoft in 2012 and has been increasingly popular over the last couple of years. Many think of TypeScript as a superset of JavaScript with an incredible developer backing and tools for learning. Since its birth in 2012, many companies have shifted to use this powerful language. Companies including Slack, Vox Media, and our very own Medium. Why? What’s so great about TypeScript?

Photo by Emily Morter on Unsplash

These were questions I had myself and after a couple of months working with TypeScript, I’ve found a few reasons why. But before that, let’s look at how it works.

TypeScript uses a structural type system that checks the shape of an object. You can think of this as a requirement. When you add a type to a variable, it needs to match the exact shape of the object. In comparison, we have nominal type systems and checks types based on whether x is an instance of a class. This can sometimes be problematic as x can be changed.

Types, types, baby

It is often found that the main difficulty in using JavaScript is describing intent. Let’s take a look at the example below.

add.js

What does this function do? From what we can see it looks to be adding a and b together. But what are the types of arguments it expects? It could be anything. Now, look at this example below.

add.ts

We know for sure that it only excepts two numbers which will be added together. The addition of types creates a much clearer view of what is happening here in regards to the types of arguments this function accepts and its output.

Complex abstraction made possible

TypeScript supports OOP concepts like interfaces, inheritance, and classes which allows developers to implement more abstract software patterns safely.

The example below shows a vehicle class with several properties written in JavaScript. You can see that creating a new car and assigning a value to a property that doesn't exist is allowed.

This is not the case using TypeScript. As we can see in the example below, when you try to assign a value to a property that doesn’t exist, an error occurs. ‘Type string is not assignable to type number’. This prevents bugs where data is changed into a form it should never exist.

Pool of opportunities

There are 12.4 million JavaScript developers in the world, almost double that of Python developers. Since TypeScript is closely related to JavaScript, these developers will find the transition incredibly smooth. With its many advantages, companies are switching over providing a huge range of jobs. It is safe to say there will be no TypeScript developer shortages anytime soon.

As we have seen TypeScript is pretty amazing, providing a safety net that allows us to catch errors early on rather than having our customers finding it for us (yikes). Its in-editor auto-complete aids us in building scalable code in a neatly, more organised fashion as well as creating an incredible pool of jobs worldwide. Like many have said before me, it’s surely Javascript that </scales>.

--

--

Claudynn Lee

Entrepreneur, amatuer writer, fitness enthusiast and software developer. Fresh perspectives coming at you every month. Watch this space 🔥