Home TechnologyTech News A comprehensive guide to Typescript for JavaScript developers

A comprehensive guide to Typescript for JavaScript developers

A comprehensive guide to Typescript for JavaScript developers

If you are a JavaScript developer, you must have heard about Typescript at one point or another. If you have been reluctant about giving Typescript a try because you are not sure how it could serve you better than JavaScript, you have come to the right place.

This guide gives an introductory but comprehensive guide to Typescript any JavaScript developer would need to get started with it.

What is Typescript, what is its type system, and how would it benefit you as a JavaScript developer to use Typescript in your next project? You will find answers to all these questions by the end of this article.

Note: I may be a bit biased towards Typescript. There’s no project that I start where I prefer JS to Typescript.

What is Typescript?

You can think of Typescript as a language that provides an additional layer over JavaScript.


Although we initially write our code in Typescript, we can’t directly run Typescript on a browser like we run JavaScript. Instead, Typescript goes through an additional compilation step to convert its code into browser-recognized JavaScript.

So, even when we program in Typescript, the end-program that runs on the browser will be in JavaScript.

Then, why do we use Typescript at all?

Though Typescript doesn’t provide additional functionalities than JavaScript at runtime, it offers a set of features to ensure that we, the developers, can write less error-prone and better maintainable code compared to when using just JavaScript.

How does Typescript do that?

Typescript, as the name suggests, introduces a type system on top of vanilla JavaScript. Whereas with JavaScript, the type of variable is dynamically assigned, Typescript forces us to pre-define the type of the variable we are declaring.

With JavaScript, we can assign an integer value to a variable in the first line and assign a string value to it in the next.

But with Typescript, we can restrict this behavior by explicitly declaring a type for a variable. If we try to assign a string to a variable of type “number,” it generates an error.