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.
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.
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.
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?
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.