TypeScript is quickly becoming a fan favorite in the JavaScript community, adding the age-old concept of types to our beloved language. This dynamic addition is changing the way developers write code and is quickly becoming an essential skill in modern web development.
In this article, we'll understand what is TypeScript, its benefits & uses, and much more!
So, without any more delays, let's START!
According to the official docs, TypeScript is a typed superset of JavaScript. But what does that mean?
You can think of it as a layer on top of Javascript!
But why a layer?
Javascript engines can't read Typescript. So, to make it readable/executable, Typescript code goes through a "pre-translation" process called compilation.
During this compilation process, the TypeScript code is stripped of its type annotations and other TypeScript-specific constructs, resulting in plain JavaScript code. That's why we can consider typescript as "a layer" on top of JavaScript.
We use tsc (TypeScript Compiler) to convert the TypeScript code into JavaScript.
Here comes the interesting question!
Why do we even need TypeScript? It's ultimately converting to JavaScript! So, we'll directly write Javascript Code!
You also had this feeling, Right?
But let me tell you, TypeScript brings a package of benefits to the table.
It helps us to catch mistakes before they mess up the whole code. Also, it makes the code well-structured and almost self-documenting.
We'll explore TypeScript's Benefits in the next section.
The main benefits of using TypeScript are:
Many developers have this question whether they should learn JavaScript or TypeScript!
Well, the answer is pretty simple!
We can't learn TypeScript without learning JavaScript. TypeScript is basically JavaScript with extra smarts for type checking. So, whatever you'll learn in JavaScript will help you learn TypeScript!
The setup of TypeScript is pretty straightforward.
To install typescript, globally run the Following Command in your terminal!
npm install -g typescript
Enter fullscreen mode. Exit fullscreen mode.
This will install typescript globally in your system!
To verify the installation, run the following command:
tsc -v
Enter fullscreen mode. Exit fullscreen mode.
This will give the current version number.
Now, create a file_name.ts
file, and write your first TypeScript code! To compile the TypeScript file, run the following command.
tsc file_name.ts
Enter fullscreen mode. Exit fullscreen mode.
This will create a file_name.js
file and add the compiled JS code.
If you found this blog post helpful, please consider sharing it with others who might benefit. You can also follow me for more content on Javascript, React, and other web Development topics.
For Paid collaboration mail me at: [email protected]
Connect with me on Twitter, LinkedIn, YouTube, and GitHub.
Thank you for Reading :)