TypeScripttsconfig options
"include" and "exclude"
Which files the compiler takes into account, and which it skips.
Example
#JSON
{
"compilerOptions": {
"strict": true
},
"include": ["src", "types/**/*.d.ts"],
"exclude": ["node_modules", "dist", "**/*.spec.ts"]
}Definition and usage
#The include and exclude fields sit at the top level of tsconfig.json, next to compilerOptions. include takes a list of file patterns, for example ["src"] or ["src/**/*.ts"], and exclude removes some of them.
By default, without include, the compiler takes all TypeScript files in the project folder, and exclude by default skips node_modules and the outDir folder.
The exclude field doesn’t block a file if another file in the project imports it. It only removes starting points of the search.
Syntax
#Syntax
"include": ["src"],
"exclude": ["node_modules", "dist"]Good practices
#- Limit
includeto the folders with code. The compiler runs faster, and the editor doesn’t analyze unnecessary files. - Add your own type declaration files (
*.d.ts) toinclude, otherwise the compiler won’t see them.
Related entries
#- "outDir" and "rootDir"The folder where compiled code goes, and the folder of the sources.
- "paths"Path aliases in imports, e.g. @/components instead of ../../components.
- "strict"Turns on a set of the most important, rigorous compiler checks.
- declare and .d.ts filesDescribing the types of something that exists outside your TypeScript code: global variables, JavaScript libraries, and modules.
Spotted a mistake or missing an example? Write to us.