Script Valley
TypeScript: Complete Course from Zero
TypeScript FoundationsLesson 1.2

How to install TypeScript and compile your first file

Node.js requirement, npm install typescript, tsc command, tsconfig.json basics, compiling ts to js, running output

Installing TypeScript

TypeScript runs on Node.js. Install it globally or as a dev dependency:

# Global install
npm install -g typescript

# Per-project (recommended)
npm install --save-dev typescript
npx tsc --version

Your first TypeScript file

Create hello.ts:

const greeting: string = "Hello, TypeScript";
console.log(greeting);

Compile and run:

npx tsc hello.ts
node hello.js

TypeScript produces a hello.js file โ€” the types are gone, it's pure JavaScript.

tsconfig.json

For real projects, initialize a config file:

npx tsc --init

This creates tsconfig.json. The three settings you need immediately:

{
  "compilerOptions": {
    "target": "ES2020",
    "strict": true,
    "outDir": "./dist"
  },
  "include": ["src/**/*"]
}

target sets the JavaScript version to output. strict enables the full set of type checks โ€” always turn this on. outDir keeps compiled files separate from source.

Run npx tsc from the project root to compile everything in src/.

Up next

TypeScript primitive types: string, number, boolean, null, undefined

Sign in to track progress

How to install TypeScript and compile your first file โ€” TypeScript Foundations โ€” TypeScript: Complete Course from Zero โ€” Script Valley โ€” Script Valley