/flags/typescript/tsc-showconfig
tsc --showConfig: print the final tsconfig after extends and defaults
- tool
- TypeScript
- command
- tsc
- flag
- --showConfig
- default
- off (tsc compiles the project)
- since
- TypeScript 3.2
tsc --showConfig prints the configuration that tsc would actually use, as JSON, and exits without compiling. The output merges every extends level, applies command-line overrides, expands include/exclude globs into the concrete files list and adds options implied by others. It is the quickest way to answer "which target am I really using?" in a project with shared base configs.
Resolving extends and overrides
npm init -y >/dev/null
npm install --silent --no-audit --no-fund typescript@7.0.2 >/dev/null 2>&1
mkdir -p configs src
echo 'export const ok = true;' > src/index.ts
echo 'export const t = 1;' > src/index.test.ts
cat > configs/base.json <<'EOF'
{ "compilerOptions": { "strict": true, "target": "es2020", "module": "nodenext", "types": [] } }
EOF
cat > tsconfig.json <<'EOF'
{ "extends": "./configs/base.json", "compilerOptions": { "target": "es2022", "outDir": "dist", "rootDir": "src" }, "include": ["src"], "exclude": ["src/**/*.test.ts"] }
EOF
npx tsc --showConfig; echo
echo "== with --noEmit on the command line"
npx tsc --showConfig --noEmit | grep -E '"(noEmit|target)"'
ls dist 2>/dev/null || echo "no dist folder: nothing was compiled"Output
{
"compilerOptions": {
"module": "nodenext",
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"target": "es2022",
"types": [],
"moduleResolution": "nodenext",
"moduleDetection": "force"
},
"files": [
"./src/index.ts"
],
"include": [
"src"
],
"exclude": [
"src/**/*.test.ts"
]
}
== with --noEmit on the command line
"noEmit": true,
"target": "es2022",
no dist folder: nothing was compiledThe target from the project file (es2022) wins over the base (es2020), strict and module come from the base, moduleResolution and moduleDetection appear because module: nodenext implies them, and the test file is gone from files because of exclude. Command-line options such as --noEmit show up in the output too.
What the output contains
| Part | What you see | Use it to check |
|---|---|---|
| compilerOptions | Merged options from every extends level plus command-line flags | Which value wins when several configs set it |
| Implied options | Settings derived from others, e.g. moduleResolution from module | Whether module and resolution match |
| files | Every source file matched by include minus exclude | Why a file is (not) compiled |
| references | Project references, if any | Build order for tsc -b |
| Missing keys | Options left at their default are not printed | Nothing: look up the default in the tsconfig reference |
Common uses
tsc --showConfig > resolved-tsconfig.json # snapshot for code review or a bug report
tsc -p tsconfig.build.json --showConfig # check a non-default config
tsc --showConfig | grep -A3 '"paths"' # verify path aliases after extends- Monorepos: shared bases in
@org/tsconfigpackages make the effectivestrictormodulesettings hard to trace;--showConfigshows the result in one place. - Migrations: after changing
module,moduleResolutionortarget, confirm the merged value before chasing errors such as TS5108. - "File not included" problems: if a file is missing from
files, the error is ininclude/exclude, not in the code.
Pitfalls
- Relative paths in the output are relative to the config that was loaded. A path that looks wrong often comes from a base config whose
outDirwas resolved from its own folder; see tsc -p. --showConfigreports the config it found by the normal lookup (current folder, then parents). Run it from the folder you build in, or pass the config with-p.- The output is the resolved config, not a valid replacement for the original:
extendsis gone and globs are expanded, so do not commit it as your newtsconfig.json.
FAQ
Does tsc --showConfig compile or type check anything?
No. It reads the configuration, resolves extends and file globs, prints the JSON and exits. No files are written and no type errors are reported.
Why does --showConfig list options I never set?
It prints some options that other settings imply, such as moduleResolution derived from module. Options that are simply at their default value are not listed, so a missing key means the default, which the tsconfig reference documents for each option.
How do I see which files are compiled and why?
The files array of --showConfig lists the matched files. For the reason each file is included, including files pulled in by imports and type packages, run tsc --explainFiles.