TypeScript is a powerful, open-source programming language developed and maintained by Microsoft. It builds on JavaScript by adding optional static types, interfaces, and modern ES6+ features, making large-scale application development easier, more reliable, and helping you catch errors early. If you’re ready to take your JavaScript to the next level, here’s a step-by-step guide to get you started with installing TypeScript. 

Key Benefits:

  • Type safety
  • Improved code readability
  • Powerful tooling with IDE support
  • Easier debugging
  • Better scalability for large projects

Prerequisites: Node.js and npm

Before installing TypeScript, make sure you have the following:

Node.js and npm installed: Node.js is a JavaScript runtime that includes npm (Node Package Manager), which we’ll use to install TypeScript.

Step 1: Check if Node.js is installed

Open your terminal or command prompt and run:

If you see a version number, Node.js is installed. If not, download and install it from https://nodejs.org. After installation, verify npm:

Step-by-Step Installation of TypeScript

Step 2: Install TypeScript Globally

Now that you have npm ready, install TypeScript globally so you can use the tsc (TypeScript Compiler) command from anywhere:

The -g flag installs TypeScript globally on your machine.

Step 3: Verify TypeScript Installation

Once installed, check the TypeScript version to confirm everything worked:

You should see something like:

Congratulations! TypeScript is now installed.

Step 4: Initialize a TypeScript Project (Optional but Recommended)

If you’re starting a new project, it’s best to initialize a tsconfig.json file that contains TypeScript configuration settings. Navigate to your project folder and run:

This will generate a tsconfig.json file. You can customize it according to your project needs.

Step 5: Writing Your First TypeScript Code

Create a new file called hello.ts:

Now compile it to JavaScript using:

This will generate a hello.js file. Run it using Node.js:

Output:

Optional: Installing TypeScript Locally (Per Project)

Sometimes, you might want to install TypeScript only for a specific project:

  1. Initialize npm in your project folder:

  2. Install TypeScript locally:

You can then run the compiler via:

This ensures everyone working on the project uses the same TypeScript version.

Installing TypeScript is straightforward, even for beginners. With just a few steps, you unlock a powerful toolset that helps you write better, safer, and more maintainable code. Happy coding with TypeScript!

Install TypeScript

Leave a Comment