Code Reference

tsconfig Basics

TypeScript · Reference cheat sheet

tsconfig Basics

TypeScript · Reference cheat sheet


📋 Overview

tsconfig.json tells the TypeScript compiler how to check and emit your project. One config at the repo root (or package root) is the usual starting point.

🔧 Core concepts

Option areaExamplesRole
compilerOptionsstrict, target, moduleHow to check/emit
include / exclude["src"]Which files belong
filesRareExplicit file list
extends"@tsconfig/node20"Share base configs
Project referencesAdvancedMulti-package monorepos

Turn on strict: true early — it enables a bundle of safer checks.

💡 Examples

Beginner-friendly Node config:

{
  "compilerOptions": {
    "target": "ES2022",
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "outDir": "dist",
    "rootDir": "src"
  },
  "include": ["src"]
}

Create a starter config via CLI:

npx tsc --init

Check without emitting JS:

npx tsc --noEmit

Browser / bundler-oriented snippet:

{
  "compilerOptions": {
    "target": "ES2022",
    "module": "ESNext",
    "moduleResolution": "Bundler",
    "jsx": "react-jsx",
    "strict": true,
    "noEmit": true
  },
  "include": ["src"]
}

⚠️ Pitfalls

  • Wrong rootDir / include pulls in node_modules or test junk.
  • target too old or too new can confuse beginners — ES2020+ is a solid default.
  • Mixing "module": "CommonJS" with ESM import needs care.
  • Editing tsconfig without restarting the editor language service can show stale errors.

On this page