TypeScript Reference ยท tsconfig: Projects, Files and Watch Options
TypeScript files, include and exclude options
Reference for the tsconfig files, include and exclude fields: glob wildcards, default values, how imports pull in extra files, and common surprises.
Three top-level tsconfig fields decide which files make up a program. files is an explicit list of paths, nothing more. include is a list of glob patterns that select files. exclude removes files from what include matched. They are siblings of compilerOptions, not part of it.
If you give neither files nor include, the compiler takes every .ts, .tsx and .d.ts file in the tsconfig's folder and below. exclude then defaults to node_modules, bower_components, jspm_packages and the outDir. Anything the selected files import is pulled into the program too, even when it matches exclude.
{ "include": ["src/**/*"], "exclude": ["src/**/*.test.ts"] }
Try it
Patterns use * (any characters within one folder name), ** (any number of folders) and ? (one character). This small matcher shows how they select files.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.
Syntax
{ "files": ["src/main.ts", "src/types.d.ts"], "include": ["src/**/*", "tests/**/*"], "exclude": ["**/*.spec.ts", "dist"] }
| Name | Description |
|---|---|
files |
An exact list of files. Missing files are an error. No wildcards. |
include |
Glob patterns. A pattern ending in a folder name with no extension means all supported files inside it. Default: **/*. |
exclude |
Glob patterns removed from include's result. Does not affect files or imported files. |
Usage notes
- Supported extensions are
.ts,.tsx,.d.ts, and withallowJsalso.jsand.jsx;.mts,.ctsand their outputs follow the same rule. excludeonly filtersinclude. To keep a file out of the program, make sure nothing imports it.- If
filesis set andincludeis not, only the listed files are roots. - When using
extends,files,includeandexcludefrom the child replace the parent's; paths resolve relative to the config that defines them. - List
distinexcludeif it is not covered byoutDir, otherwise built.d.tsfiles may be picked up. tsc --listFilesprints what ended up in the program, which is the quickest way to debug a surprise.