paint-brush
How to Get Started With TypeScriptby@arindam1729
333 reads
333 reads

How to Get Started With TypeScript

by Arindam Majumder May 17th, 2024
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

TypeScript is a typed superset of JavaScript. TypeScript catches errors at compile time rather than at the run-time. It makes the code well-structured and makes it almost impossible to mess up. It's also easier to self-document and make the code easier to read.
featured image - How to Get Started With TypeScript
Arindam Majumder  HackerNoon profile picture

Introduction

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!

What Is TypeScript?

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.

Why TypeScript?

Getting Started with TypeScript in React: A Comprehensive Guide

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.

Benefits

The main benefits of using TypeScript are:

  • Early error detection: TypeScript catches errors at compile time rather than runtime. This helps avoid bugs that are harder to fix later.


  • Better code readability: Type annotations make the code more self-documenting and easier to read/understand.


  • IntelliSense: IDEs can provide code completions and suggestions based on the static type information.


  • Improved tooling: Tools like linters and refactors work better with static typing information.


  • Better for large apps: Static typing scales better for large applications and codebases.

Should I Learn JavaScript or TypeScript?

IntelliSense

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!

Setting Up 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.

Conclusion

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 :)