The tsconfig.json
file specifies the root files and the compiler options required to compile a TypeScript project. So presence of a tsconfig.json
file in a directory indicates that the directory is the root of a TypeScript project. Without that file, the compiler will continue to move up the directory hierarchy to fine the config file.
There is also a jsconfig.json
file. It acts almost the same, but has some JavaScript-related compiler flags enabled by default. We’re just going to focus on the tsconfig.json
file for now.
From the TypeScript documentation:
A project is compiled in one of the following ways:
Using
tsconfig.json
orjsconfig.json
- By invoking tsc with no input files, in which case the compiler searches for the
tsconfig.json
file starting in the current directory and continuing up the parent directory chain.- By invoking tsc with no input files and a
--project
(or just-p
) command line option that specifies the path of a directory containing atsconfig.json
file, or a path to a valid.json
file containing the configurations.When input files are specified on the command line, files in
tsconfig.json
are ignored.
What’s Inside the JSON file?
JSON files, as we’ve discussed previously, allow us to easily store information in key-value pairs. Here are some common keys you will find in the config file:
files
The files property includes an array of strings related to file names. These files will be imported into the project, and if one is not found, an error will be generated.
"files": [
"core.ts",
"sys.ts",
"types.ts",
"scanner.ts",
"parser.ts",
"utilities.ts",
"binder.ts",
"checker.ts",
"emitter.ts",
"program.ts",
"commandLineParser.ts",
"tsc.ts",
"diagnosticInformationMap.generated.ts"
]
include and exclude
You can also use the include and exclude properties, which is an array of files, relative to your project, will search for a file names, and or patterns to include, or exclude, when compiling your project.
"include": ["src/**/*"],
"exclude": ["**/*.spec.ts"]
More?
There is actually a lot more that goes into the file, and you can find a starter document here: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html
You can find an even more detailed list of attributes that can be configured in the file here: https://www.typescriptlang.org/tsconfig/
What is tsconfig.json for? was originally found on Access 2 Learn