This tutorial explains How to install typescript installation.
Typescript is available as a node package, You can use npm, and yarn to install.
Typescript can be installed in multiple ways
- Global Installation
- Local Project installation
How to install typescript globally
The following are steps required to install typescript global installation
You can use the below command
npm install -g typescript
It installs the typescript and compiler into the global npm location and adds tsc command to environment variables
next, Check the Typescript compiler version
A:\>tsc --version
Version 4.8.3
- project installation
In node projects, Run the below command as devDependencies in a project
npm install typescript --save-dev
This adds the below entry in package.json
"devDependencies": {
"typescript": "4.8.3",
}
and, installs a typescript compiler in the node_modules folder of a project
Hello World Typescript program
Once typescript is installed, the tsc
command is available and ready to use
First, Open any text editor or VSCode
Create a hello.ts file and add the below code
console.log("Hello World Typescript first program");
save the file.
- Open the terminal, run the below command
tsc hello.ts
It generates hello.js in the current directory and contains the below code.
console.log("Hello World Typescript first program");