tsconfig Basics

View saved

Generate a config

In a project folder with TypeScript installed, create a starter config.

npx tsc --init

Set common options

Start with strict checking and clear input/output folders.

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

Compile the project

With a tsconfig present, run tsc with no file arguments.

tsc

Useful flags to know

  • strict enables a bundle of safer checks
  • noImplicitAny forbids silent any
  • lib chooses built-in type libraries (ES, DOM)
  • Adjust module to match Node ESM or your bundler

Comments

One comment per signed-in account. Comments are saved with this page’s URL.