Setup
With Vite (recommended)
Vite handles TypeScript out of the box. No separate compile step.
npm create vite@latest my-app -- --template vanilla-ts
cd my-app
npm install
npm run dev
Standalone Compiler
For scripts or Node.js projects without a bundler:
npm install -D typescript
npx tsc --init # creates tsconfig.json
Run a file:
npx tsx index.ts # tsx = TypeScript execute (no build step)
tsconfig.json Essentials
{
"compilerOptions": {
"strict": true,
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "bundler",
"skipLibCheck": true,
"noUncheckedIndexedAccess": true
}
}
| Option | What it does |
|---|---|
strict | Enables all strict checks (always use this) |
target | JS version to emit |
moduleResolution: "bundler" | Modern resolution for Vite/webpack projects |
noUncheckedIndexedAccess | Array/object indexing returns T | undefined |
Gotcha:
skipLibCheck: trueskips type checking of.d.tsfiles. This speeds up compilation but can hide issues in third-party type definitions. Keep it on for most projects.