TypeScript Setup

Summary: in this tutorial, you’ll learn how to set up a TypeScript development environment.

The following tools you need to set up to start with TypeScript:

  • Node.js – Node.js is the environment in which you will run the TypeScript compiler. Note that you don’t need to know node.js.
  • TypeScript compiler – a Node.js module that compiles TypeScript into JavaScript. If you use JavaScript for node.js, you can install the ts-node module. It is a TypeScript execution and REPL for node.js
  • Visual Studio Code or VS Code – is a code editor that supports TypeScript. VS Code is highly recommended. However, you can use your favorite editor.

If you use VS Code, you can install the following extension to speed up the development process:

  • Live Server – allows you to launch a development local Server with the hot reload feature.

Install Node.js

To install node.js, you follow these steps:

  • Go to the node.js download page.
  • Download the node.js version that suits your platform i.e., Windows, macOS, or Linux.
  • Execute the downloaded node.js package or execution file. The installation is quite straightforward.
  • Verify the installation by opening the terminal on macOS and Linux or the command line on Windows and typing the command node -v. If you see the version that you downloaded, then you have successfully installed node.js on your computer.

Install TypeScript compiler

To install the TypeScript compiler, you launch the Terminal on macOS or Linux and Command Prompt on Windows and type the following command:

npm install -g typescript

After the installation, you can type the following command to check the current version of the TypeScript compiler:

tsc --v

It should return the version like this:

Version 4.0.2Code language: CSS (css)

Note that your version is probably newer than this version.

If you’re on Windows and got the following error:

'tsc' is not recognized as an internal or external command,
operable program or batch file.Code language: Shell Session (shell)

… then you should add the following path C:\Users\<user>\AppData\Roaming\npm to the PATH variable. Notice that you should change the <user> to your Windows user.

To install the ts-node module globally, you run the following command from the Terminal on macOS and Linux or Command Prompt on Windows:

npm install -g ts-node

Install VS Code

To install the VS Code, you follow these steps:

  • Navigate to the VS Code download page.
  • Download the latest version of VS Code that suits your OS (Windows, macOS, or Linux)
  • Execute the downloaded package or the installer file to launch the setup wizard. The installation process is also quite straightforward.
  • Launch the VS Code.

You’ll see the VS Code as shown in the following picture:

To install the Live Server extension, you follow these steps:

  • Click the Extensions tab to find the extensions for VS Code.
  • Type the live server to search for it.
  • Click the install button to install the extension.

In this tutorial, you’ve learned how to install a development environment for working with TypeScript.

Was this tutorial helpful ?