Skip to content
TypeScript ts getting-started 3 min read

Installing TypeScript

Getting TypeScript onto your machine takes one command, but where you install it matters. The recommended approach is a per-project (local) dev dependency so every contributor and your CI pipeline use the exact same compiler version — TypeScript’s behavior can change subtly between minor releases. This page covers installing TypeScript with the major package managers, the difference between global and local installs, verifying the install, and the editor integration that makes the whole experience worthwhile.

Prerequisites

TypeScript runs on Node.js, so install a current LTS version of Node first (which bundles npm). Verify it before continuing.

node --version   # v22.x or any active LTS
npm --version

Any reasonably recent Node release works. If you use a version manager like nvm, fnm, or volta, pin a Node version per project for consistency.

Add TypeScript as a development dependency. This keeps the compiler version locked in package.json and shared across your team, the CI server, and future you.

# npm
npm install --save-dev typescript

# pnpm
pnpm add -D typescript

# yarn
yarn add --dev typescript

# bun
bun add -d typescript

A local install puts the tsc binary in node_modules/.bin. Run it through your package manager so it resolves to the project version rather than any global one.

npx tsc --version    # npm
pnpm tsc --version   # pnpm

Global install (use sparingly)

A global install gives you tsc anywhere on your system, which is handy for quick experiments but risky for real projects because the version is not tracked.

npm install --global typescript
tsc --version    # e.g. Version 5.8.x

Reserve global installs for throwaway scripts. For anything committed to a repo, prefer the local install so builds are reproducible.

AspectLocal (per-project)Global
Version trackingLocked in package.jsonUntracked, machine-wide
Team consistencyIdentical for everyoneVaries per machine
Invocationnpx tsc / pnpm tsctsc
CI friendlinessReproducible buildsFragile
Best forReal projectsQuick experiments

Verify the installation

After installing, confirm the compiler is available and check its version. TypeScript follows semantic-ish versioning where minor bumps can introduce new checks.

npx tsc --version
# Version 5.8.3

If the command prints a version number, you are ready to compile. If you see “command not found,” make sure you installed locally and are invoking via npx/pnpm/yarn.

Initialize a tsconfig.json

Most projects need a tsconfig.json to configure the compiler. Generate a commented starter file with the --init flag.

npx tsc --init

This creates a tsconfig.json with strict enabled and sensible defaults. You can edit it afterward; the tsconfig overview walks through the key options.

Pin the TypeScript version exactly (e.g. "typescript": "5.8.3", not "^5.8.3") in shared projects. A minor upgrade can introduce new errors, and you want that to be a deliberate, reviewed change rather than a surprise.

Editor integration

Visual Studio Code ships with TypeScript language support built in, so type-checking and autocomplete work the moment you open a .ts file. To ensure the editor uses your project’s installed version rather than its bundled one, select “TypeScript: Select TypeScript Version → Use Workspace Version” from the command palette.

// .vscode/settings.json
{
  "typescript.tsdk": "node_modules/typescript/lib"
}

Pinning the workspace version guarantees the squiggles you see in the editor match the errors your CI build will report.

Best Practices

  • Install TypeScript as a local dev dependency so the version is tracked and reproducible.
  • Invoke the local compiler via npx/pnpm/yarn rather than relying on a global binary.
  • Pin an exact version in shared repositories to avoid surprise errors on minor upgrades.
  • Run tsc --init to scaffold a tsconfig.json with strict defaults.
  • Configure your editor to use the workspace TypeScript version for consistent diagnostics.
  • Keep Node on an active LTS release and pin it per project with a version manager.
Last updated June 29, 2026
Was this helpful?