Lesson 28 +10 XP

tsconfig.json & Essential Compiler Options

tsconfig.json Configuration & Compiler Options

The tsconfig.json file specifies root files and compiler options required to compile a TypeScript project.

Creating a tsconfig.json

Generate a default configuration file using:

tsc --init

Essential Compiler Options

OptionRecommended SettingPurpose
target"ES2022" or "ESNext"Target JavaScript language version emitted.
module"NodeNext" or "ESNext"Module system specification for output code.
stricttrueEnables all strict type-checking options.
noImplicitAnytrueRaises error on expressions with implied any type.
strictNullCheckstrueEnsures null and undefined are handled explicitly.
outDir"./dist"Output directory for compiled .js files.
rootDir"./src"Root directory of input TypeScript files.

Sample tsconfig.json

{
  "compilerOptions": {
    "target": "ES2022",
    "module": "commonjs",
    "rootDir": "./src",
    "outDir": "./dist",
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true
  },
  "include": ["src/**/*"]
}

TL;DR

  • Run tsc --init to generate a starter tsconfig.json.
  • Always set "strict": true for maximum safety.
  • Use outDir and rootDir to organize build inputs and outputs cleanly.