Typescript- Why we must use it in our JS projects ?
Hi folks ,
Today I have decided to discuss about TypeScript with you all , When I started to write my applications with Typescript , the first question that came to my head was , Why we have to use Typescript when we can write the same code with Javascript alone? , So I began to start studying about the importance of typescript and what benefits we are getting out of it
let's answer the basic question , What is TypeScript ?
Typescript is generally a type system , it is not a separate language like javascript ,it's a Superset of Javascript which means any javascript file is a typescript file .
If any Javascript file is a typescript file then why we are using Typescript specifically in our projects ?
Typescript is an extension of Javascript from this we can get an idea that typescript is going to give additional features to our Javascript code to meet our important needs
When Javascript was developed it was just meant to do some interactive actions on our browsers , later on it has become a language which we can use in any platform , Therefore it has given a privilege of building large applications when our application grows , managing it becomes a tedious task
Typescript is a language for application scale Javascript development , this helps us to write huge applications with Javascript and we can maintain it easily
As we all know Javascript is a loosely typed language it allows us to do many nonsensical things which may end with bugs to tackle these kind of bugs we must use typescript
Typescript helps us to write better code at zero cost , whenever a Typescript is compiled it just returns plain Javascript So, we are not going to lose because of Typescript , rather we are going to gain some significant benefits
As a React Developer we are creating alot of Reusable components when we re-use them we might forget or miss to pass a particular prop to that component which can be highlighted in our IDE when we use Typescript this can be found out even while we write our code and that prevents unwanted Runtime errors
领英推荐
let's see a small example , in which we want to add a number twice
const addNumbers = (val)=>{
return val + val
}
addNumers("hello")
The above code will work fine without throwing any error in normal Javascript but
we won't be getting the expected output
If we write the same code with Typescript
const addNumbers = (val)=>{
return val + val
}
addNumers("hello")
this will throw a compiler error when we try to excute this code , this is how
typescript helps us to write better Javascript code
In my coming articles will write about , how to use Typescript efficiently with React and Node JS and the idea of this article is to give brief introduction to Typescript , Hope you did like it !
Thanks for your time,
VMKrishna