TypeScript is a programming language for web development based on JavaScript. It makes the code clearer and more robust, adds static typing (variables are bound to specific data types), and can be compiled into JavaScript. TypeScript is used by frontend and backend developers, adding several advanced features to JavaScript. The most important is strict typing (enabled by default but can be disabled if the developer doesn’t want to use it). In addition, TypeScript provides many useful improvements such as Interfaces, Mixin classes, Enums, and many more, which is described in detail in the next article.

Why is TypeScript gaining more and more followers?

If a brief description of the main advantages of TypeScript wasn’t enough to convince you to use TypeScript, there is more:

  • Errors made during code modification are visible immediately, not at runtime;
  • TypeScript helps to write complex solutions that are easier to develop and test;
  • The language is easy to learn;
  • TypeScript has a high compilation speed and is distributed under the Apache license.

TypeScript solves the biggest problem of JavaScript. Namely, an error can only be detected during the execution of code in JavaScript. Sooner or later, this leads to buggy applications and negatively affects any business by degrading the user experience. TypeScript eliminates this problem by checking for underlying issues at compile time.

Data in JavaScript is stored in variables and has some type: string, number, logical value. In JavaScript, the typing is dynamic. This means that you can assign a numeric value to one variable first and then, for example, a text value.

TypeScript adds strict typing to the language. Each variable at creation is assigned a particular type – a standard or created by the developer. You can create a type within the limits of the language. For example, the number from 1 to 31 to record a day in a month, or an array of digits to record coordinates.

The object-oriented approach

The object-oriented approach (OOP) treats the information it deals with as classes and objects. An object is a complex instance of data, and a class is the “blueprint” or “framework” from which objects are created. An object has a class, just as a variable has a type.

TypeScripthas features enable OOP, but only partially. The language supports classes and objects, enough for immediate actions. But, for example, it does not work with access modifiers-so called the ability to make some part of a class “open” or “closed” for outside access.

 TypeScript supports three modifiers:

  • Public – elements with this modifier are accessible from anywhere without any restrictions. This modifier is set by default.
  • Private – elements with this modifier are only available from the class where they are defined.
  • Protected – elements with this modifier are available from the class in which they are defined and in subclasses/derived classes.

TypeScript adds many OOP features to JavaScript: access modifiers, abstract classes, and other features.

High Project Speed

TypeScript helps reduce the time it takes to identify and fix bugs that are sometimes hard to find in a dynamic JavaScript environment. With TypeScript, you can write more understandable and readable code that describes the subject area as much as possible. In this way, the architecture becomes more pronounced.

How TypeScript works

Code written in TypeScript will not execute directly in a browser. That’s why TS is not a stand-alone language. It requires additional step – transpilation – when the software converts the code written in TypeScript into “pure” JavaScript.

Over the years, TypeScript has become very popular. Whereas previously, it was primarily used to write web applications, now it is even used to write the logic for websites and much more. For example, developers of Angular 2, the platform for creating applications, chose TypeScript over JavaScript. The same applies to MedTech app and even Visual Studio Code from Microsoft.