Why Create TypeScript
Next, we will take a closer look at the distinctive features of both languages and how they affect the development process.
Differences in typing
Yes, you can set additional conditions in the code that prohibit the user from performing certain actions or entering data that can “break” the entire code. However, this requires additional time and testing.
In the case of TypeScript, the user simply cannot enter another data type than a number, since this is the type used throughout the function. True, the user will not receive any message by default – the action simply will not be performed, but the code will not break. Additionally, you can write different warnings for such cases, but this is not necessary, since it does not affect performance in any way. True, in the function code, all variables will have to set data types. It’s not too difficult, but it can be tedious when writing large volumes.
This feature is associated with different logic for performing typing. For static ones, all data types that the program or function will work with are already predefined. If you try to use another data type, if it cannot be adapted to the specified type, the program simply will not run further. In the case of dynamic typing, data types do not have to be specified in the code, as they will be adjusted automatically. This saves a little time and simplifies development a little, but increases the likelihood of errors.
With TypeScript, everything is easier – you can check individual pieces of code right in the editor. And all this without the need to run the program itself. So you can be sure that the check will not be affected by the execution of other functions and you will get the result exactly for the piece of code you are interested in. The simplified check became possible just thanks to static typing.
Compatibility between languages
An IDE or development environment helps make it easier to write code. Unlike conventional text or code editors, they have many useful features for the developer: code navigation, syntax highlighting, error correction recommendations, built-in compiler and debugger. Using full-fledged IDEs not only makes the programmer’s work more comfortable, but also improves the quality of the finished code.
TypeScript supports most popular development environments and code editors. Among them: WebStorm, Visual Studio Code, Atom, Eclipse and others. If they don’t have support enabled by default, it can easily be added using third-party free plugins.
TypeScript full OOP
This means that code written in TS will have support for such basic components as: classes, inheritance, interfaces, arrays, objects, and much more. The concept of OOP makes it easy to create well-organized, scalable code, making TypeScript a great choice for growing projects.
Refactoring and Lightweight Code Working
Refactoring is the process of improving code while developing or maintaining an existing project. In fact, its main task is to improve readability, facilitate support by other developers. At the same time, the functionality should not change in any way – the program or part of it works the same as before. TypeScript is doing great in terms of refactoring due to:
Excellent IDE compatibility. Due to the fact that errors and syntax are highlighted automatically, it is very easy to make changes to the project.
There are built-in hints for some common mistakes. For example, you changed the name of a function, but forgot to replace it in other places where it occurs. Since other program components will refer to a non-existent function, an error will occur. IDEs that support TypeScript warn of such gaps, which allows you to quickly make changes to all names.
Disadvantages of TypeScript
The features discussed above are more likely to be the advantages of TypeScript. However, it has its drawbacks, which also need to be considered.
- Need subordination
If we are talking about a development team, then it would be nice if it develops its own coding standards and begins to conduct regular code reviews. This way it will turn out to reveal all the possibilities of TypeScript to the maximum.
- Incomplete control over data types
- Difficulty using third party libraries
What’s next for TypeScript
How to install typescript
It, unlike JS, will not work normally without first installing certain packages. First you need to install Node.js. In general, all web developers should have it, as it is necessary to support many tools. Node.js is installed by analogy with regular programs: go to the official website, download the required version and install it like a regular program.
Along with Node.js, the npm package manager will be installed on your computer. With its help, TypeScript is installed:
- Open npm panel in terminal. This can be done even in the code editor by simply launching the built-in terminal.
- Write the command there: npm install -g typescript and press Enter to apply.
- Wait a while for the packages to install. You will not receive completion notifications. You can verify that the installation is correct using the tsc -v command. After executing it, you will see the current version of TypeScript on your computer.