tsconfig.json is a configuration file used by the TypeScript compiler to understand how to transpile your code. Its folder is the root of the project: running tsc there compiles the files it describes.

Create one with:

npx tsc --init

Example

tsconfig.json
{
  "compilerOptions": {
    "target": "ES2022",
    "module": "nodenext",
    "outDir": "dist",
    "rootDir": "src",
    "strict": true,
    "noUncheckedIndexedAccess": true,
    "skipLibCheck": true
  },
  "include": ["src"]
}
Top-level keyDescription
compilerOptionsHow to check and emit the code (the tables below).
includeFiles or folders to compile (glob patterns allowed).
excludeFiles to skip from include (default: node_modules and outDir).
extendsInherits options from another config, e.g. a shared base file.

Below are some of the most commonly used options grouped by category.

Core Options

OptionDescriptionExample
targetJavaScript version to output"ES2022"
moduleModule system to use (nodenext, esnext, etc.)"nodenext"
moduleResolutionHow imports are found (nodenext, bundler)"bundler"
libInclude built-in libraries["ES2022", "DOM"]
types@types packages to load globally["node"]
allowJsAllow JavaScript files to be compiledtrue
checkJsEnable type-checking for JS filestrue
outDirOutput directory for .js files"dist"
rootDirRoot directory of input .ts files"src"
Which module setting? Code that runs in Node.js: "nodenext". Code bundled by Vite, webpack or similar: "esnext" with "moduleResolution": "bundler".

Strictness Options

OptionDescriptionExample
strictEnable all strict type-checking optionstrue
noImplicitAnyDisallow variables with any type unless explicitly typedtrue
strictNullChecksDisallow assigning null/undefined to other typestrue
strictFunctionTypesEnforce function parameter type compatibilitytrue
noUncheckedIndexedAccessIndex access (arr[0], obj[key]) may be undefinedtrue

strict turns on a whole family of checks, including noImplicitAny, strictNullChecks and strictFunctionTypes. noUncheckedIndexedAccess is not part of it and has to be enabled separately.

Code Quality & Behavior

OptionDescriptionExample
noUnusedLocalsWarn about unused variablestrue
noUnusedParametersWarn about unused function parameterstrue
noEmitOnErrorDon't emit .js if there are type errorstrue
noImplicitOverrideRequire override on methods that override a base methodtrue
resolveJsonModuleAllow importing .json filestrue
skipLibCheckSkip type checking of declaration files (.d.ts)true
declarationGenerate .d.ts files (for libraries)true
sourceMapGenerate source maps for debuggingtrue

Changes in TypeScript 6.0 and 7.0

Older guides and configs may not match current behavior:

SettingNow
stricttrue by default. Set "strict": false to opt out.
moduleDefaults to esnext. amd, umd, systemjs and none are gone.
targetDefaults to the latest ECMAScript version. ES5 is no longer supported.
typesDefaults to []: list @types packages you need, e.g. ["node"].
rootDirDefaults to the folder containing tsconfig.json.
esModuleInteropAlways on; it can't be set to false anymore.
moduleResolution: "node" / "classic"Removed. Use nodenext or bundler.
baseUrl, outFile, downlevelIterationRemoved.

See the TypeScript 6.0 and 7.0 release notes for the full list.