tsconfig
tsconfig.json is the file that tells the TypeScript compiler which files to include and which checks and emit settings to use. tsc looks for it starting from the current directory and walking up.
Detailed Explanation
A TypeScript project is not "every .ts file on disk." It is the set of files described by a tsconfig.json. That file has two jobs: which files (include, exclude, files, references) and how to treat them (compilerOptions).
compilerOptions is the large object. A few groups matter more than the rest.
Type checking: strict and its family, plus extras such as noUncheckedIndexedAccess and exactOptionalPropertyTypes. These change which programs are legal. They do not change the emitted JavaScript except for alwaysStrict.
Module system: module, moduleResolution, esModuleInterop, resolveJsonModule, allowSyntheticDefaultImports. These decide how import is resolved and how it is emitted. Wrong values here produce "cannot find module" errors that look like missing packages.
Language level: target is the JavaScript you emit. lib is the type definitions you assume exist at runtime (ES2022, DOM). target and lib are related but not the same: you can emit ES2018 and still type-check against ES2022 APIs, which then crash if the engine does not have them.
Emit: outDir, rootDir, declaration, declarationMap, sourceMap, noEmit. Libraries usually emit .js plus .d.ts. Applications that use a bundler often set noEmit and let the bundler transpile, while tsc is used as a type-checker (tsc --noEmit).
Interop with JS: allowJs, checkJs, maxNodeModuleJsDepth. Useful on a migration, noisy if left on forever.
extends lets one config inherit another. Monorepos use a root tsconfig.base.json for shared compiler options and per-package configs that set include and references. files and include in the child replace the parent's file set; compilerOptions are merged, with the child winning on conflicts.
tsc -p path/to/tsconfig.json builds that project. tsc --showConfig prints the merged result, which is the first thing to look at when two tools disagree about your settings. Editors read the nearest tsconfig.json to decide which options apply to a file; a file not included in any config is treated with looser inferred options, which is why "it errors in CI but not in the editor" usually means the file is outside include.
Keep one source of truth. Duplicating flags in tsc CLI arguments, a bundler plugin, and tsconfig.json is how strict ends up on in the editor and off in the build.
Code Examples
1. A typical application config that type-checks and lets a bundler emit.
// 1. A typical application config that type-checks and lets a bundler emit.
{
"compilerOptions": {
"target": "ES2022",
"lib": ["ES2022", "DOM"],
"module": "NodeNext",
"moduleResolution": "NodeNext",
"strict": true,
"noEmit": true,
"skipLibCheck": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true
},
"include": ["src"]
}2. A library that emits JS and declaration files.
// 2. A library that emits JS and declaration files.
{
"compilerOptions": {
"target": "ES2020",
"module": "NodeNext",
"declaration": true,
"declarationMap": true,
"outDir": "dist",
"rootDir": "src",
"strict": true
},
"include": ["src"]
}3. A package that extends a shared base.
// 3. A package that extends a shared base.
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
},
"include": ["src"],
"references": [{ "path": "../shared" }]
}Common Gotchas
A file outside `include` is not in the project
the editor may still type-check it with inferred options, and CI (which uses `-p tsconfig.json`) will ignore it or fail to see its exports. Put the file in `include` or add a second config.
`target` does not load typings; `lib` does
emitting ES2015 while calling `Array.at` type-checks if `lib` includes ES2022, then crashes on older engines.
`tsc --showConfig` prints what the compiler actually uses after `extends`
read that before comparing two tools.
`skipLibCheck` skips type errors inside `node_modules` `.d.ts` files
it speeds builds and can hide a broken dependency. Turn it off when you are debugging a types mismatch in a library.