exclude filters the files that include matched. Its patterns work the same way, relative to the config file, and by default it leaves out node_modules and two older package folders.
What it does not do surprises most people: it does not keep a file out of the program. If an included file imports an excluded one, the excluded file is read, and with checkJs on, checked and reported, as the example shows. To stop checking a file that is still imported, put // @ts-nocheck at its top.
At a glance
| Write | Folders inside an include pattern that the checker should not start from, such as ["src/vendor"]. It does not stop imports |
|---|---|
| On the command line | No flag: only a config file can set it |
| Type | string[] |
| Default in TypeScript 5.9 | ["node_modules", "bower_components", "jspm_packages"] (plus outDir when one is set) |
| Description in the tsconfig.json schema | Specifies a list of files to be excluded from compilation. |
The description is quoted from the tsconfig.json schema published by SchemaStore (Apache-2.0), which carries the descriptions TypeScript does not ship for top-level keys; see the notices.
Examples
export function pad(text) {error TS7006: Parameter 'text' implicitly has an 'any' type.
return text.padStart(3, "0");
}jsconfig.json for this example
{
"compilerOptions": {
"checkJs": true,
"noEmit": true,
"strict": true,
"target": "es2022",
"module": "nodenext",
"types": []
},
"include": [
"src/**/*.js"
],
"exclude": [
"src/legacy"
]
} When exclude helps
For files nothing imports: build output, vendored copies of libraries, fixtures, a scratch folder. Those are the files that only reach the program through include, so exclude really keeps them out.
Gotchas
- Setting
excludereplaces the default list, but there is no need to addnode_modulesback: in TypeScript 5.9 a**pattern inincludenever walks intonode_modulesanyway.
Sources
- TSConfig Reference: exclude · TypeScript
- TypeScript 2.0 release notes · TypeScript handbook
- tsconfig.json schema · SchemaStore
Last reviewed 20 October 2026.