Overview
Thetsconfig.json file is the configuration file for TypeScript projects. It specifies the root files and compiler options required to compile your project.
The presence of a
tsconfig.json file in a directory indicates that the directory is the root of a TypeScript project.Basic Structure
Atsconfig.json file has the following top-level properties:
tsconfig.json
Configuration Properties
compilerOptions
ThecompilerOptions property is the most important part of your configuration. It specifies the compiler settings for your project.
include
Specifies an array of filenames or patterns to include in the program. These filenames are resolved relative to the directory containing thetsconfig.json file.
The patterns work like
.gitignore: ** matches any directory nested to any level, * matches zero or more characters, and ? matches any one character.exclude
Specifies an array of filenames or patterns that should be skipped when resolvinginclude.
node_modulesbower_componentsjspm_packagesoutDir(if specified)
files
Specifies an allowlist of files to include in the program. An error occurs if any of the files can’t be found.extends
Inherits configuration from another file. The value can be a relative or absolute path.- Load base file configuration
- Override with properties from the extending file
- All relative paths in the inherited config are resolved relative to the config file they originated from
references
Project references enable TypeScript projects to be structured as independent units. See Project References for detailed information.Real-World Examples
Node.js Application
tsconfig.json
Browser Application with React
tsconfig.json
TypeScript Compiler (from source)
This example is from the TypeScript compiler’s owntsconfig-base.json:
src/tsconfig-base.json
Library with Declaration Files
tsconfig.json
Watch Options
Configure how the watch mode works:Watch File Strategies
Fromsrc/compiler/commandLineParser.ts:288-302:
fixedPollingInterval- Check every file at fixed intervalpriorityPollingInterval- Check files at different intervals based on heuristicsdynamicPriorityPolling- Use dynamic queue that updates less frequently modified filesfixedChunkSizePolling- Check files in chunksuseFsEvents- Use file system events (default)useFsEventsOnParentDirectory- Use file system events on parent directories
Type Acquisition
Configure automatic type acquisition for JavaScript projects:src/compiler/commandLineParser.ts:1795-1822:
enable- Enable automatic type acquisitioninclude- Type declaration packages to includeexclude- Type declaration packages to excludedisableFilenameBasedTypeAcquisition- Disable inferring types from filenames
Initializing a tsconfig.json
Use the TypeScript compiler to create a newtsconfig.json file:
Programmatic API
ts.parseConfigFileTextToJson()
Parse a tsconfig.json file content into a configuration object.The name of the config file (used for error reporting)
The JSON content of the config file as a string
config: The parsed configuration objecterror: A diagnostic if parsing failed
Example
tsconfig.json file with default compiler options and helpful comments.
Schema Validation
Thetsconfig.json file supports JSON schema validation in most modern editors:
Best Practices
Use strict mode
Always enable
"strict": true for new projects to catch more errors at compile time.Enable source maps
Use
"sourceMap": true for better debugging experience.Skip lib checks
Use
"skipLibCheck": true to speed up compilation by skipping type checking of declaration files.Use project references
For large projects, use project references to improve build times and enforce module boundaries.
Common Patterns
Multiple tsconfig files
Many projects use multiple configuration files:Monorepo setup
tsconfig.json (root)
Related Documentation
Compiler Options Reference
Complete list of all compiler options with types and defaults
Project References
Learn how to structure large TypeScript projects