Skip to the workspace
Pebellslearn by building
Type Inference  ›  Lesson

tsconfig.json

tsconfig.json 12 mintsconfig.json marks the root of a TypeScript project and says which files to compile and with which compiler options.

typescript / tsconfig.json

Explore each scene at your own pace.

01 · The rule

The rule

tsconfig.json

tsconfig.json marks the root of a TypeScript project and says which files to compile and with which compiler options.

Connect project files and compiler settings through one reproducible configuration.

Run npx tsc in a folder, and how does the compiler know which files to check, how strict to be, or where to write the JavaScript? It reads one file: tsconfig.json. Everything about how your project compiles lives there.

The rule

tsconfig.json marks the project: which files, which options, which output.

The folder containing tsconfig.json is the root of a TypeScript project. When you run tsc without file names, it looks for this file in the current folder and then in parent folders.

A small configuration for the task tracker:

{
  "compilerOptions": {
    "target": "ES2022",
    "module": "NodeNext",
    "rootDir": "src",
    "outDir": "dist",
    "strict": true
  },
  "include": ["src"],
  "exclude": ["src/**/*.test.ts"]
}

The top-level keys answer "which files?":

  • include — folders or patterns to compile. "src" means every TypeScript file under src/.
  • exclude — patterns to leave out of what include matched. (node_modules is excluded by default.)
  • files — an exact list of files, used instead of or alongside include in small projects.
  • extends — inherit settings from another config file, such as a shared base for several packages.

compilerOptions answers "how?":

  • rootDir and outDir — where the sources live and where the .js files go. src/tasks/list.ts becomes dist/tasks/list.js, keeping the folder structure.
  • target and module — what kind of JavaScript to produce (the next lesson covers these).
  • strict — how hard to check.

The file allows comments, unlike ordinary JSON, which is why tsc --init fills it with explanatory notes.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.