Sub topic 16
Seeing the Configuration the Compiler Really Uses
Assume you know basic TypeScript syntax, can run tsc from a terminal, and can read JSON configuration files. This chapter shows how to investigate a project when TypeScript appears to ignore an option or compile an unexpected file.
Why the visible `tsconfig.json` may not be enough
TypeScript can combine settings from several sources:
- A local
tsconfig.json - A configuration named with
--project - A parent configuration loaded through
extends - Command-line options
- Defaults chosen by the compiler
The configuration file is also interpreted from its own directory. For example, "include": ["src"] means the src directory next to that configuration file.
When you run tsc without a file name, TypeScript searches for tsconfig.json in the current directory and then in parent directories. If the project contains multiple configuration files, you may be checking one file while the command uses another.
Use --project to select a configuration explicitly:
npx tsc --project packages/api/tsconfig.json --noEmit--noEmit performs type checking without writing JavaScript or declaration files.
Print the effective configuration
--showConfig prints the configuration after TypeScript resolves inherited settings and defaults.
npx tsc --project tsconfig.json --showConfigThe output is JSON. It commonly contains compilerOptions, files, and other resolved settings. This makes it useful for checking questions such as:
- Did
"strict": trueenable the expected checks? - Did a child configuration override
"module"? - Did
"extends"load the file you expected? - Did an option such as
"noUncheckedIndexedAccess"remain enabled? - Which files did the configuration select?
For a large output, save it temporarily or pipe it to a JSON tool:
npx tsc --project tsconfig.json --showConfig > effective-tsconfig.jsonThe generated file is diagnostic output, not a replacement for your source configuration. Do not edit it expecting TypeScript to use those changes.
List every file in the compilation
--listFiles prints the files that TypeScript includes in the compilation. It lists both your project files and library declaration files, such as the declarations that describe JavaScript built-ins.
npx tsc --project tsconfig.json --noEmit --listFilesUse --listFilesOnly when you want only the file list and fewer diagnostics:
npx tsc --project tsconfig.json --listFilesOnlyIf a source file is missing, inspect include, exclude, and files. If an unexpected file appears, check inherited configuration and the patterns in include. The exclude option affects automatic discovery, but a file named directly in files or imported by another source file can still be part of the program.
flowchart TD
A[Run tsc] --> B{Which project?}
B -->|--project path| C[Use the specified tsconfig]
B -->|No --project| D[Search from the current directory]
C --> E[Resolve extends and options]
D --> E
E --> F[Select files]
F --> G[Type-check and optionally emit]caption: How TypeScript determines the project and its effective file set alt: A flowchart showing tsc selecting a configuration, resolving inherited options, selecting files, and then checking and emitting them.
A practical debugging sequence
When configuration behavior is surprising, use the same sequence each time:
- Identify the command and working directory used by the build.
- Add
--projectso the intended configuration is explicit. - Run
--showConfigand inspect the resolved options. - Run
--listFilesOnlyand inspect the resolved file set. - Run
--noEmitto isolate type-checking errors from output problems. - Compare the effective configuration with the source configuration and its parent files.
Exercise
Which command shows the final inherited configuration without generating JavaScript?
Show answer
npx tsc --project tsconfig.json --showConfig prints the resolved configuration. Add --noEmit when running a normal type-check command to prevent output files.