The popularity of Typescript in modern front end web development has been increasing enormously. So, why is everyone talking about it? What is it?
When an argument is passed, it can hold any data type or value; we won’t know for sure what attributes does that argument hold. Hence, we will need to put logs to track down what is being passed from the place where the function is called. This, in essence, is a bit tedious.
Typescript solves that.
In a function in Typescript, we can quickly grasp an understanding of what type of arguments does it take, what type of value does it return, what external data does it require and what it does to them to generate the return value from the IDE itself.
TypeScript always points out the compilation errors at the time of development. Because of this, the chance of getting errors at the run-time is very less. Also with strict type checking, the common typos can be easily identified and fixed. Let's take an example from the above function. A minor typo like this could be easily identified during development.
Setup Correct Development Workflow
In Typescript, you first need to think about the type of data you’ll receive, and the type of data you want to produce. Usually, only after that, you sit down for its’ implementation. It also helps in the TDD approach for visualizing and writing test cases with the proper input and output datasets.
Easier Code Review
Typescript gives you another assurance check: the typedef compilation check. If the whole thing compiles and unit tests are there, you can be pretty sure that the whole thing works well. It makes it easier to trust other developers and aids in faster code review.
When refactoring codes, we become little hesitant when it touches many files, for example, renaming components, changing your object, removing deprecated attributes. With Typescript, it aids us in such refactoring by throwing an error whenever our changes have caused any type mismatches in other parts of the code. Also, with some cool IDE command features like “Find All Occurrences” and “Rename Symbol” we don’t need to rely on Search and Replace.
Ease Of Development In A Large Codebase
We have a clear signature of the imported function. Any changes in it will be easily identifiable where it is being used.