What Each Option Does
| Option | What it does |
|---|---|
target | The JavaScript version to output. ES2022 works in Node.js 18+ and modern browsers. |
module, moduleResolution | NodeNext follows how Node.js loads ES modules and CommonJS. For a Vite or webpack app, use "ESNext" and "Bundler". |
lib | Which built-in type definitions are available. Add "DOM" for browser code. |
outDir, rootDir | Where the compiled files go, and where your source files are. |
strict | Turns on all strict type checks. Strongly recommended. |
esModuleInterop | Makes importing CommonJS packages with import work smoothly. |
skipLibCheck | Skips type checking of .d.ts files in node_modules, for faster builds. |
forceConsistentCasingInFileNames | Catches imports that differ only in upper/lower case. |
resolveJsonModule | Lets you import .json files. |
declaration, sourceMap | Writes .d.ts type files and source maps for debugging. |
noUncheckedIndexedAccess | Treats array and object lookups as possibly undefined, which prevents many bugs. |
include, exclude | Which folders TypeScript checks and which it ignores. |
Tips
- Run
npx tsc --initto create a tsconfig.json with every option listed as a comment. - Check the compiled settings with
npx tsc --showConfig. - tsconfig.json may contain comments (it is read as JSONC), but plain JSON like this template works with every tool. Read more in our JSON comments guide, and format a tsconfig.json that has comments with the JSON5 and JSONC Formatter.
Frequently Asked Questions
What is tsconfig.json?
tsconfig.json tells the TypeScript compiler which files to check and how to compile them, for example which JavaScript version to output and how strict to be.
Can tsconfig.json have comments?
Yes. TypeScript reads tsconfig.json as JSONC, so comments and trailing commas are allowed. Other tools may not accept them, so this template is plain JSON.
Should I turn on strict?
Yes, for new projects. strict turns on a group of checks that catch many bugs early, such as values that might be null or undefined.