Understand tsconfig.json

tsconfig.json defines the files and compiler behavior for a TypeScript project. Important options include target (JavaScript language level), module and moduleResolution (how imports are emitted and resolved), rootDir and outDir (source/output layout), strict (strict type-checking family), and noEmit (check without output).

Do not treat compiler flags as isolated switches. For example, Node's ESM rules differ from browser bundler resolution. A project should use a configuration aligned with its deployment target and build system. Extend a framework-provided configuration when the framework expects one.

A simple Node project config
{
  "compilerOptions": {
    "target": "ES2022",
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "rootDir": "src",
    "outDir": "dist",
    "strict": true,
    "noEmitOnError": true
  },
  "include": ["src/**/*.ts"]
}
💡 This is a starting example for a modern Node ESM-oriented project, not a universal config. NodeNext behavior also depends on package metadata and file extensions. Frontend projects may use moduleResolution: "Bundler" or framework defaults.
Key Takeaways
  • target controls the JavaScript syntax level.
  • module and moduleResolution must agree with the environment.
  • strict enables a family of checks; noEmitOnError can prevent output after errors.
Knowledge Check

Which option enables the strict family of type-checking options?