Why we Love Typescript – the Power of Javascript, Plus More…

Here’s our case for why we love Typescript, and why you should try it out, too. Typescript isn’t opinionated, and can co-exist nicely alongside Javascript. Which makes it far more likely to stick around for the long term. It also just happens to be an excellent language to work with.

Anyone in front-end software development knows Javascript frameworks and front-end tools go in and out of fashion faster than the blink of an eye. 

But something makes Typescript different from typical projects in the Javascript hype cycle.

Typescript isn’t opinionated, and can co-exist nicely alongside Javascript. Which makes it far more likely to stick around for the long term. It also just happens to be an excellent language to work with.

So, here’s our case for why we love Typescript, and why you should try it out, too.

(Before we jump in, here’s a quick definition of Typescript: Typescript is a superset of Javascript, with the addition of syntax for (optional) static typing. Typescript is transpiled down to Javascript, and thus runs anywhere Javascript runs.) 

We love Javascript (and so does Typescript)

A love letter about Typescript has to start with Javascript — because that’s where Typescript starts, too. The idea of Typescript is simply to take Javascript and add the ability for static types to it. We’ll get to what that means and enables in a moment, but we need to first start off with Javascript, because Javascript itself is excellent.

When we say “Javascript is excellent”, we aren’t talking about the language itself. Any Javascript developer can point out many incidents where the language falls short. But Javascript has a few important things going for it:

  • it works both client-side and server-side
  • It’s everywhere, which makes it easy to recycle and reuse code 

Another benefit of Javascript is that it is mostly backwards compatible. That is to say: if you take a piece of the web from 2000 and run it now, it will basically run the same. That alone is, in many ways, Javascript’s killer feature. It means that the platform everyone builds on is incredibly stable. Even if the Javascript ecosystem might look incredibly fickle and fast-changing, the Javascript language is the opposite. 

When Microsoft engineers started to develop Typescript, they borrowed that same concept of interoperability and backwards compatibility: Typescript is a syntactic superset of Javascript, and thus offers everything that Javascript is… plus more. All Javascript code is valid Typescript code, but with Typescript a developer can also add static types that compile down to Javascript. You thus get all the good stuff of Javascript, plus a static types system.

Typescript brings a static type system to Javascript

What makes a static type system such a significant addition? Because it allows any developer to quickly catch more bugs, and avoid relatively easy mistakes — something no one is immune to. You thus can write safer code, faster.

For a real life example: Airbnb conducted a post mortem analysis after switching their code to Typescript. 38% of their bugs were preventable with Typescript!

Static types allow developers to clearly and explicitly define the objects and functions they are working with. It allows them to make the language more explicit, and this in turn allows the compiler to quickly spot where things are going wrong. And the Typescript compiler is incredibly powerful for catching easy mistakes.

With the addition of certain tooling, even more bugs and issues can be caught. For example, a library like Zod allows you to define a schema and validate that the code you write is valid with that schema. You give it an object, and Zod will return the same object where the type is the schema. Now you can guarantee that types are consistent with the schema.

Other projects like the TypeScript ESLint library bring a powerful linting tool, ESLint, to the world of Typescript to create assertions called lint rules around what your code should look or behave like.

All these upgrades allow a developer to work towards a better organised, more secure and stronger typed Javascript codebase, where type definitions are explicit rather than implicit, which makes all reasoning clearer and more tangible.

Typescript can be layered in gradually

This brings us to the next big benefit of Typescript: any project can layer in Typescript gradually, over time. Since all Javascript is valid in Typescript, one can make the switch to Typescript without any real migration pains — the adaptability and ability to co-exist with Javascript is outstanding. 

That’s good for small projects, and essential for larger projects. For the latter, it is impossible to suggest to your CTO or client to “rewrite the whole thing in a new language” — that doesn’t work. What Typescript allows you to do instead, is gradually add types, and over time improve the type awareness of your code base. Better yet: you’ll immediately unlock the abilities of the Typescript compiler to catch small bugs that you wouldn’t have spotted otherwise. As your type awareness grows, so does the soundness of your types. 

Typescript will thus never force you to do anything The Typescript Way, nor will it present any big hurdles when switching over. Typescript really is, as the title of this article suggests, everything that Javascript is… plus more.

You don’t even have to write all those types yourself

A strongly typed language sounds great, but who is going to write all those brittle type definitions? Who wants all that extra work of explicitly defining every last detail?

The answer is nobody. Which is no problem, because the compiler does most of it. In fact, if you take existing Javascript code and open it with any modern IDE, you immediately get many of Typescript’s benefits. While at that stage, the compiler won’t have any explicitly defined types to look at, it will be able to infer a great deal based on analysing the existing code. 

The IDE can thus really streamline your development workflow, and, assuming it can infer a lot from simply looking at your Javascript code, it can also start helping. Think about inference, auto-completion, and documentation for instance.

In general, by collaborating more closely with your IDE, it becomes much easier to understand what you’re working with. You can work with a certain function, and better understand what to do, what it does, and what can happen with it. 

Given that javascript itself is dynamic, one can pass anything to it without receiving any errors. When bugs pop up, however, the problem is that it’s necessary to understand all the code they are embedded in. The rabbit hole, so to speak, is very deep. With Typescript by contrast, we can use simple type definitions to get to the end of our proverbial rabbit hole faster. Once a good percentage of code is typed, we can use it as documentation and to compartmentalise the code  (and thus the bugs). The stronger we type our code over time, the smaller the compartments will become, and thus the easier it becomes to back trace bugs and errors.

In conclusion, we’re ambassadors for doing things the Typescript way. Even though Typescript brings a small additional layer of overhead and additional tooling into a project, the benefits compared to vanilla Javascript are abundant. Typescript makes the switch easy, and the rewards come almost immediately.

As the project grows and strengthens its types, the benefits of Typescript accumulate and reinforce. After a while, it simply results in more readable code that is easier to manage and easier to maintain. This is especially useful when more new developers come on to the project. 

Are you a front-end developer that would like to work with Typescript? Consider hopping over to our hiring page, and see what positions we have open —  we’re nearly always hiring for senior technical talent, so you might fit right in!

Share:

Related posts

Let’s shape your ideas
together

No sales pitch or commitments. Just an honest talk to see if it’s a good fit
and build our cooperation from there.
 
You can also contact us via email contact@vacuumlabs.com

By submitting this form you agree to the processing of your personal data according to our  Privacy Policy.

Message sent

Thank you for contacting us! One of our experts will get in touch with you to learn about your business needs.