What is TypeScript?
TypeScript is a programming language first developed by Microsoft in 2012. Its main ambition is to improve the productivity of developing complex applications.
- Readability. Thanks to the addition of strict types and other elements that make the code more self-expressive, you can see the design intent of the developers who originally wrote the code. This is especially important for distributed teams working on the same project. A code that speaks for itself can compensate for the lack of direct communication between team members.
- IDE support. Type information renders editors and integrated development environments (IDEs) much more useful. They can offer features like code navigation and auto-complete, providing accurate suggestions.
- The power of object-orientation. TypeScript supports Object-Oriented Programming (OOP) concepts such as classes, interfaces, inheritance, etc. The OOP paradigm makes it easier to build well-organized scalable code, and this advantage becomes more apparent as your project grows in size and complexity.
- The support of a talented community. Behind TypeScript is a massive community of very gifted people working day by day to improve the language.
Typescript and NodeJS
Why choose TypeScript for your next project?
When TypeScript was new, some developers were a little reluctant to learn the new skills.
However, over time, many have come to appreciate it. The strength of TypeScript is not felt in the first moments of a project’s life but over the long term.
This language is evolving rapidly, and the developers’ community continues to grow. As a result, new versions are regularly released and make it easier to get started with TypeScript, use it daily, and add even more powerful features. In fact, TypeScript ranks number ten in The PYPL PopularitY of Programming Language Index.
Once comfortable with the language, it’s clear that developers have a better understanding of the code and the libraries used.
But the most important and revolutionary aspect that it brings for front-end developers is auto-completion. Back-end developers should find this amusing because this is something they’ve known for a long time! But for front-end developers, this is one of the main advantages of TypeScript.
It acts as living documentation, allowing tools (IDE) to offer relevant and reliable auto-completion.
Programming and Objects
$ npm install -g typescript
In common with other programming languages, TypeScript contains the following data types:
String — A string is a sequence of characters
Integer — An integer data type is a non-decimal number
Float — A float is a number with a comma or a number
Boolean — A Boolean represents TRUE or FALSE.
Array — An array stores multiple values in a single variable.
How to install TypeScript
Before going further, you must install the following tools:
– Vs code: which is currently the IDE par excellence for the language
After having installed them following the instructions of their respective sites, you must follow the following installation steps:
Create your project folder. Let’s name it, for example, project_startup
Open your vscode code editor then click File->open folder ->select project_startup
After the npm init command, you will be prompted to set up your project. Press Enter to keep the default configuration.
There are lots of coding examples online for more detail.
One of TypeScript’s main principles is that type checking concentrates on the shape of values. This is sometimes referred to as “duck typing” or “structural subtyping”. In TypeScript, interfaces have the function of naming these types and are an effective way of defining contracts within the code in addition to contracts with code away from your project.
Working with large projects
In general, it does not matter which one you choose. The most important question is whether it meets your needs. Anyway, there are some reasons why TypeScript deserves special attention.
Some final thoughts
The advantage of TypeScript, as mentioned above, is, therefore, mainly for developers.
TypeScript is also very useful and efficient when the day comes for code redesigns or factorizations. If a code module changes its behaviour, the development team will be automatically alerted wherever this module is used and implemented. Therefore, the team will be more serene and secure in the redesign, thus improving the maintainability of a project over time.
As mentioned before, the code is more readable and easier to understand, makes it easy to onboard new developers to a project, and reduces the cost of entry (which can be quite colossal on large-scale projects).
The advantage also for a start-up will be to attract slightly more experienced and rigorous developers within their company, thus increasing the quality of the applications produced and internal projects.
Want to discover more about TypeScript? Watch the video below!