iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

Installing TypeScript

Install TypeScript per-project, not globally. Pin the version in package.json so CI and every developer's machine use the same compiler.

Quick install

SHELL
# In a project root
npm init -y
npm install -D typescript @types/node
npx tsc --init     # generates tsconfig.json

Why -D (dev dependency)

You only need TypeScript at build / test time. At runtime, the deployed JavaScript runs without it. Installing as devDependency keeps production installs lean.

Scripts to add

package.json
{
    "scripts": {
        "build":      "tsc",
        "build:watch":"tsc -w",
        "type-check": "tsc --noEmit",
        "start":      "node dist/index.js",
        "dev":        "tsx watch src/index.ts"
    }
}

Other package managers

npmpnpmyarnbun
npm install -D typescriptpnpm add -D typescriptyarn add -D typescriptbun add -d typescript

Useful supporting packages

PackageWhy
@types/nodeTypes for Node's built-in modules.
tsxRun .ts files directly — modern ts-node replacement.
typescript-eslintESLint + TS rules.
@tsconfig/node20 (or your version)Curated tsconfig preset.
vitestFast TS-friendly test runner.

Editor — use the workspace TS version

VS Code: Cmd/Ctrl+Shift+P → "TypeScript: Select TypeScript Version" → "Use Workspace Version". Otherwise your editor's bundled TS might be older or newer than CI's.

Tip: Pin the exact version with "typescript": "5.6.2" (no caret). One less moving part across machines and CI — and TS minor releases occasionally tighten checks.

Example

Example
// Local install (recommended):
//   npm install -D typescript @types/node
//   npx tsc --init
//
// Or pnpm / yarn — same packages.
// 'tsc -w' watches for changes; 'tsc --noEmit' just type-checks.
console.log('Pin TS in package.json so CI uses the same version');
Try it Yourself »

Exercise

Install TypeScript as a dev dependency.

npm install typescript

Test yourself

Q1. Install TypeScript as…
Q2. Editor should use…
Q3. Pin TS exactly with…

Discussion

Loading…