Background Повернутись

Why you should choose TypeScript?


  TypeScript was introduced as programming language based on JavaScript in 2012 and till now developing rapidly.
For those that have doubts whether it worth to turn to TypeScript we want to argue some pluses.
The first and the most significant advantage of TypeScript is its statistic typing. It means that:
-    Less code. Defining the type by one time variable, we don’t need to write big amount of checking during every usage of this avariables.
-    As a rule, statistically typified languages are quicker.
-    It allows revealing some mistakes on the compilation stage.

     The type Enum deserves special attention. It is very comfortable data type when we have some numeral or textual meanings herewith we will compare another data. Although it’s important to bear in mind that Enum is always textual or appropriate numeral meaning. For example, with the help of Enum you can make constants some object characteristics.
     Assume, we have characteristic of flat template and we want to find out how many flats suit to our template.

Compiled JavaScript:

    From this example, we see that in TypeScript we have a more understandable and readable code. Also, having created our data type - the interface IFlat - we are sure that all objects of the array have the properties we need and we cannot make checks.
In another case you can make our template a constant.

Compiled JavaScript JavaScript:

As you can see, there is no such object as Flat in JavaScript at all, but thanks to TypeScript, we know for sure that this is a figure 3 under conditions and even a year later, we can easily understand the code and make edits.
TypeScript allows you to use the scope for variables, properties, and methods. Thanks to private / public, we can be certain that nobody will have access to those properties / methods / variables that are not intended for external access and will not break the code.
Another plus is the ease of turning to TypeScript in an existing project. After all, any JavaScript code is a valid TypeScript.
That is, to go to an existing project on TypeScript, simply change the file extension from .js to .ts and then write to TypeScript again. Everything is very simple, is not it?
It is also worth noting that one of its disadvantages is that it is not a standard. However, TypeScript has more advantages over the ES6 standard. Both TypeScript and ES6 are not supported by browsers and are compiled in JavaScript. Schematically this can be shown as follows:

ESP6, like TypeScript, supports classes and modules, articulation functions, etc., but it does not have the types and other benefits of this (for example, interfaces). And in case you want to get more structured code, it makes sense to use TypeScript.