TypeScript Compiler (tsc)
tsc stands for TypeScript Compiler.
It is a command-line tool that converts TypeScript (.ts) code into JavaScript (.js) code and performs static type checking.
1. Install TypeScript
First, make sure Node.js and npm are installed.
Install TypeScript globally:
npm install -g typescript
Check the version:
tsc --version
2. Create a TypeScript file
Create a file named app.ts:
let username: string = "Hemant";
let age: number = 32;
console.log(username);
console.log(age);
3. Compile TypeScript into JavaScript
Run:
tsc app.ts
It generates a new file:
app.ts
Source
tsc app.ts
app.js
Generated
5. Useful tsc commands
Command | Purpose |
|---|---|
| Compile one file |
| Check compiler version |
| Generate tsconfig.json |
| Compile project using tsconfig.json |
| Automatically recompile on changes |
| Check types without generating JS |
| Show available commands |