Setting Up TypeScript
Purpose: get a working TypeScript environment. Benefit: you can compile and run your first TypeScript program with confidence.
Before coding, we need setup. ## Step 1: Install Node.js TypeScript runs on Node.js. Download from nodejs.org. ## Step 2: Install TypeScript compiler ```bash npm install -g typescript ``` Check: ```bash tsc -v ``` ## Step 3: First TypeScript file Create file: app.ts ```ts let message: string = "Hello TypeScript"; console.log(message); ``` ## Step 4: Compile to JavaScript ```bash tsc app.ts ``` This creates app.js. Run: ```bash node app.js ``` ## tsconfig.json (project setup) ```bash tsc --init ``` This creates tsconfig.json which controls: - target JS version - strict mode - module system ## Graph: build cycle ```mermaid flowchart LR A[Write app.ts] --> B[tsc] B --> C[app.js] C --> D[node] ``` ## Remember - write .ts - compile to .js - run JavaScript