TypeScript Installation

As discussed in TypeScript Introduction, the browsers won’t understand the code whatever we wrote in Typescript due to that you need to install the TypeScript compiler either globally or in your workspace to compile and convert TypeScript source code to JavaScript.

 

TypeScript installation can be done in two ways:

 

  1. Using Node.js npm (Node.js package manager)
  2. Install TypeScript plug-in in IDE (Integrated Development Environment)

Install TypeScript using Node.js NPM

To install TypeScript using node.js package manager, you need to make sure that the node.js has installed on your machine. In case, if node.js not installed on your machine, install it by following node.js installation article.

 

After completion of node.js installation on your machine, open node.js command prompt and execute npm install -g typescript command to install TypeScript globally (-g) on your computer like as shown below.

 

Typescript installation using node.js npm

 

After successfully installation of TypeScript, it will show the typescript version info, etc. as shown in the above image.

 

If you would like to know the version information of TypeScript or would like to check the installation is done properly or not then execute tsc -v command in node.js command prompt like as shown below.

 

Verify installed typescript version in node.js command console

 

Now, both node.js and typescript installed on your machine so you can start writing the code using the code editor of your choice. In the next chapters, we will learn more about it.

Install TypeScript Plug-in in IDE

To write TypeScript code, you can use IDE of your choice such as Eclipse, Visual Studio, Visual Studio Code, Notepad++, WebStorm, NetBeans, etc. but you need to install TypeScript plug-in or package in your IDE to enable TypeScript development environment.

 

Following are the typescript plugins for few of popular code editors.

 

TypeScript in Visual Studio 

The Visual Studio comes with TypeScript when installing Microsoft Web Tools. You can also download TypeScript for Visual Studio 2019 and 2017 from here. For Visual Studio 2015, the TypeScript can be downloaded from here.

 

In case, if you are using Visual Studio 2013 you can download TypeScript from here.

TypeScript in Visual Studio Code Editor

Visual Studio Code is an open-source light-weight cross-platform (Windows, MacOS, and Linux) editor and it comes with built-in TypeScript support. You can download the Visual Studio Code from here.

TypeScript Online Playground

TypeScript has provided an online code editor (https://www.typescriptlang.org/play) to write and compile TypeScript code online without installing any component on your machine.

 

The online TypeScript playground will compile TypeScript code and generate the corresponding JavaScript code like as shown below.

 

Online typescript playground