Root Fields
Starting up are the root options in the TSConfig - these options relate to how your TypeScript or JavaScript project is set up.
# Files - files
Specifies an allowlist of files to include in the program. An error occurs if any of the files can’t be found.
{" ": {}," ": ["core.ts","sys.ts","types.ts","scanner.ts","parser.ts","utilities.ts","binder.ts","checker.ts","tsc.ts"]}
This is useful when you only have a small number of files and don’t need to use a glob to reference many files.
If you need that then use include
.
# Extends - extends
The value of extends
is a string which contains a path to another configuration file to inherit from.
The path may use Node.js style resolution.
The configuration from the base file are loaded first, then overridden by those in the inheriting config file. All relative paths found in the configuration file will be resolved relative to the configuration file they originated in.
It’s worth noting that files
, include
, and exclude
from the inheriting config file overwrite those from the
base config file, and that circularity between configuration files is not allowed.
Currently, the only top-level property that is excluded from inheritance is references
.
Example
configs/base.json
:
{" ": {" ": true," ": true}}
tsconfig.json
:
{" ": "./configs/base"," ": ["main.ts", "supplemental.ts"]}
tsconfig.nostrictnull.json
:
{" ": "./tsconfig"," ": {" ": false}}
Properties with relative paths found in the configuration file, which aren’t excluded from inheritance, will be resolved relative to the configuration file they originated in.
- Default:
false
- Released:
# Include - include
Specifies an array of filenames or patterns to include in the program.
These filenames are resolved relative to the directory containing the tsconfig.json
file.
json
{"include": ["src/**/*", "tests/**/*"]}
Which would include:
. ├── scripts ⨯ │ ├── lint.ts ⨯ │ ├── update_deps.ts ⨯ │ └── utils.ts ⨯ ├── src ✓ │ ├── client ✓ │ │ ├── index.ts ✓ │ │ └── utils.ts ✓ │ ├── server ✓ │ │ └── index.ts ✓ ├── tests ✓ │ ├── app.test.ts ✓ │ ├── utils.ts ✓ │ └── tests.d.ts ✓ ├── package.json ├── tsconfig.json └── yarn.lock
include
and exclude
support wildcard characters to make glob patterns:
*
matches zero or more characters (excluding directory separators)?
matches any one character (excluding directory separators)**/
matches any directory nested to any level
If the last path segment in a pattern does not contain a file extension or wildcard character, then it is treated as a directory, and files with supported extensions inside that directory are included (e.g. .ts
, .tsx
, and .d.ts
by default, with .js
and .jsx
if allowJs
is set to true).
# Exclude - exclude
Specifies an array of filenames or patterns that should be skipped when resolving include
.
Important: exclude
only changes which files are included as a result of the include
setting.
A file specified by exclude
can still become part of your codebase due to an import
statement in your code, a types
inclusion, a /// <reference
directive, or being specified in the files
list.
It is not a mechanism that prevents a file from being included in the codebase - it simply changes what the include
setting finds.
# References - references
Project references are a way to structure your TypeScript programs into smaller pieces. Using Project References can greatly improve build and editor interaction times, enforce logical separation between components, and organize your code in new and improved ways.
You can read more about how references works in the Project References section of the handbook
- Default:
false