Continuing on typescript, let's know why typescript is needed.Major two reasons are:
- Static Type checker
- Tooling
I will be referring to typescript as "TS" and javascript as "JS" from now on.
Static Type checker
Imagine what happens when we run the following code in JS
function greet(person, date) {
console.log(`Hello ${person}, today is ${date.toDateString()}!`);
}
greet("Abhirup");
It will throw a typeerror !!
console.log(`Hello ${person}, today is ${date.toDateString()}!`);
^
TypeError: Cannot read property 'toDateString' of undefined
Why? Because the date param of greet is undefined and so toDateString of undefined throws error.But we got to know of this error while running only.
Now if we paste the same code in the .ts file.
Without running our file we got to know the error(red squiggly line 6) and hence we can quickly fix it.
Tooling
It means first class support of typescript by the popular IDEs and code editors.
Check this link for more.
Whenever we hover mouse on the error "squiggly" lines, we get to know of the potential fix.Also we can "click" on the variable to check the reference etc.
Please do like and share this blog.
Top comments (3)
You don't need Typescript to get the features listed here
Hey, Joe, the above features are not supported in vanilla javascrpt. till date.
I must be from the future then