How to install TypeScript ?
- Download and install the NodeJS framework onto your computer system.
Following is the step-by-step guide to install TypeScript on:
Step 1: Go to the start menu and click on the command prompt.
Step 2: To install typescript we have to use NPM, NPM is called a node package manager. As its name suggests, it is used to install NodeJS packages onto our system.
Run the following command in the same NodeJS command prompt to install the typescript:
npm install --global typescript
The above command will install the typescript onto our local system. To verify the installation, run the following command:
Here tsc is a typescript compiler and the -v flag indicates that we are displaying the version of the typescript as shown in the image below:
At this point, typescript is successfully installed onto your system.
Step 3: To install a specific version of a typescript, use the following command with ‘@’ followed by version.
npm install --global email@example.com
Here, ‘x’ can be changed with the version that we want to install, as shown in the image below:
Step 4: To uninstall typescript, use the same command that is used to install the typescript and replace the installation with uninstall. Here is the command:
npm uninstall --global typescript
Now, let’s create a simple hello world project through typescript:
Step 1: Create a folder onto your desktop and create a file named “main.ts”. You can write whatever name you want for this file and folder.
Step 2: Open up the NodeJS command prompt and navigate to the folder path that we created in step 1.
Step 3: Run the Initialization command in that command prompt to create the necessary configuration file for our simple project.
This tsc –init command will create a configuration file for the typescript compiler called tsconfig.json. This file contains all the configurations for the typescript compiler that we will be going to use while executing the program.
Step 4: Open up the main.ts that we created in the step1. Below is the hello world code in the typescript. It will display the string in the console that will confirm the working of the typescript compiler.
Typescript main.ts Code:
The above code should be pasted and saved in the main.ts file before executing the typescript compiler.
Step 5: Run the typescript compiler with the file name as an argument to see results.
This will create a compiled JS file from that typescript file. And now to run the JS file we will be using the NodeJS as below.
Please Login to comment...