How do you compile TypeScript code?

Beginner

Answer

TypeScript code is compiled using the TypeScript compiler (tsc):

# Install TypeScript globally
npm install -g typescript

# Compile a single file
tsc app.ts

# Compile with watch mode
tsc app.ts --watch

# Compile using tsconfig.json
tsc

The compiler reads .ts files and outputs .js files that can run in any JavaScript environment.