TypeScript tsconfig and Tooling

tsconfig.json patterns, diagnostics, and project references.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## tsconfig Basics
Minimal tsconfig
{
  "compilerOptions": {
    "target": "ES2022",
    "module": "ESNext",
    "moduleResolution": "Bundler",
    "strict": true,
    "noEmit": true,
    "skipLibCheck": true
  }
}

# A small strict config for many projects.

Node-focused tsconfig
{
  "compilerOptions": {
    "target": "ES2022",
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "outDir": "dist",
    "rootDir": "src",
    "strict": true,
    "esModuleInterop": true
  },
  "include": ["src/**/*"]
}

# Example config for modern Node.js projects.

Configure path aliases
{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@/*": ["src/*"]
    }
  }
}

# Use `baseUrl` and `paths` for ergonomic imports.

Enable strict mode
{
  "compilerOptions": {
    "strict": true
  }
}

# Turn on TypeScript’s strict family checks.

Control included files
{
  "include": ["src/**/*.ts", "src/**/*.tsx"],
  "exclude": ["dist", "node_modules"]
}

# Use `include` and `exclude` patterns.

## Compiler Diagnostics and Debugging
List compilation files
npx tsc --listFiles

# Print files included in the program.

Extended diagnostics
npx tsc --extendedDiagnostics

# Measure compiler performance details.

Show resolved config
npx tsc --showConfig

# Print the final config after `extends` resolution.

Clean build artifacts
rm -rf dist *.tsbuildinfo && npx tsc --build

# Remove `.tsbuildinfo` and build outputs before recompiling.

## Project References
Composite project config
{
  "compilerOptions": {
    "composite": true,
    "declaration": true,
    "outDir": "dist"
  }
}

# Enable settings required for project references.

Reference another project
{
  "references": [
    { "path": "../shared" }
  ]
}

# Declare a dependency on a sibling TS project.

Clean project reference outputs
npx tsc --build --clean

# Use build mode clean command.

Recommended next

No recommendations yet.