Setup

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
  }
}
OptionWhat it does
strictEnables all strict checks (always use this)
targetJS version to emit
moduleResolution: "bundler"Modern resolution for Vite/webpack projects
noUncheckedIndexedAccessArray/object indexing returns T | undefined

Gotcha: skipLibCheck: true skips type checking of .d.ts files. This speeds up compilation but can hide issues in third-party type definitions. Keep it on for most projects.