Understanding TypeScript

Understand TypeScript and how it prevents bugs.

We'll cover the following

TypeScript is a feature-rich, OOP-based and compiled programming language developed by Microsoft. Most JavaScript applications are now built on TypeScript.

The TypeScript language was developed to compensate for lapses in JavaScript and to enhance the developer experience while working with applications or a large JavaScript codebase.

Why is TypeScript better?

One of the flaws in JavaScript is that it’s loosely typed.

Press + to interact
// index.js
var myName = "john doe";
myName = 400;

As we can see, a variable in JavaScript is assigned different data types such as numbers and strings. Yet, JavaScript doesn’t throw an error since it’s loosely typed and variable data types are inferred from their values.

This solution can be both good and bad. We don’t have to define types for everything we do, but as the application grows in size, we may encounter instances where some entities or variables will require a specific data type throughout the lifecycle of the application.

In TypeScript, these debugging issues rarely occur since we must declare data types for everything we do. TypeScript will always alert us when we try to change a variable data type later on.

Press + to interact
// index.ts
var myName: string = "john doe";
//this will throw an error, if executed
myName = 400;

TypeScript brings many benefits to the table and enables developers to build complex JavaScript applications with fewer errors and more functionalities.