The top-level directive include
specifies which files should be included for compilation. It is based on the location of the file relative to .tsconfig.json
and by default includes all files in the project within the **
wildcard. Files not specified in the include
directive will not be compiled.
The compilerOptions.rootDir
setting determines the root directory for the output at outDir
. By default, it identifies the common path among the included folders. For instance, in a project with files src/services/user.ts
and src/services/auth.ts
, the rootDir
would automatically adjust to src/services/
(i.e., the longest common path shared by all input files). Consequently, the output directory structure would appear as follows:
dist
├── auth.js
└── user.js
If manually specifying rootDir
as src
, the resulting output directory structure would be:
dist
└── services
├── auth.js
└── user.js
Furthermore, if there are files outside of the designated rootDir
that are included in the include
directive, an error will occur:
error TS6059: File '~/project/outside.ts' is not under 'rootDir' '~/project/src'. 'rootDir' must encompass all source files.
The file is part of the program due to:
Inclusion pattern '**/*' matches it in '~/project/tsconfig.json'