Getting Started
Install TypeScript, configure tsconfig, and run your first program.
TypeScript is a typed superset of JavaScript that compiles to plain JS. It powers large-scale front-end (React, Angular, Vue) and back-end (Node.js) applications.
Install
npm install -g typescript
npm install -g ts-node # REPL and direct execution
Verify:
tsc --version
# Version 5.x.x
tsconfig.json
tsc --init
Key settings:
{
"compilerOptions": {
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "node",
"strict": true,
"outDir": "./dist",
"rootDir": "./src",
"esModuleInterop": true,
"skipLibCheck": true
}
}
First Program
Create src/index.ts:
function greet(name: string): string {
return `Hello, ${name}`;
}
console.log(greet("TypeScript"));
Run:
# Compile and run
tsc && node dist/index.js
# Or use ts-node
ts-node src/index.ts
Project Setup
npm init -y
npm install typescript --save-dev
npx tsc --init
Next: Basics