Skip to main content

How To Initialize A TypeScript Project

The steps

From empty folder to typed project

# 1. Make sure Node is installed (use a current LTS version)
node -v

# 2. Create a package.json
npm init -y

# 3. Install TypeScript (as a dev dependency — it's a build tool)
npm i -D typescript

# 4. Generate a tsconfig.json (the compiler's config file)
npx tsc --init

# 5. Compile your .ts files to .js
npx tsc

What each piece does

  • npm init — creates package.json, the project manifest.
  • npm i -D typescript — installs the tsc compiler locally. It's a dev dependency because it only runs at build time, never in production.
  • tsc --init — scaffolds a tsconfig.json with sensible defaults and every option documented.
  • tsc — reads tsconfig.json, type-checks your code, and emits JavaScript.

Install TypeScript locally (-D), not globally. That pins the exact compiler version per project, so your build is reproducible on any machine and in CI.