Sub topic 4
Skipping declaration file checks with skipLibCheck
This chapter assumes you have read the earlier chapters on the phases of a tsc run and on measuring a baseline with --extendedDiagnostics. You should be comfortable editing tsconfig.json and reading the numbers tsc prints. Here you will learn what skipLibCheck skips, what it leaves alone, how to measure its effect, and what you give up by turning it on.
What the option does
A declaration file is a file ending in .d.ts. It describes types without containing runnable code. Your program loads many of them: the built-in lib.*.d.ts files that describe JavaScript and the DOM, the @types/* packages, and the .d.ts files that libraries ship next to their JavaScript.
By default, the checker verifies every one of those files, the same way it verifies your own .ts files. It resolves every name, compares every heritage clause, and reports every error. For a project with many dependencies, this adds up to a large share of the check phase.
skipLibCheck: true tells the checker not to report errors for any file ending in .d.ts. It skips the checking pass over those files. That is all it does.
Two details matter in practice:
- The option applies to all
.d.tsfiles in the program, not only those undernode_modules. A.d.tsfile you wrote or generated yourself is skipped too. - The option name suggests it skips "library" files, but TypeScript decides by file extension, not by where the file lives.
What is still done
Skipping the check pass does not remove the files from the program. The compiler still has to know what they declare, so it still does the following:
- It reads and parses every
.d.tsfile. - It binds them, which means creating the symbols that names refer to.
- It resolves the types they declare whenever your code uses them.
So skipLibCheck only reduces the check phase. It does not change parse or bind time, and it does not reduce the number of files in the program. If your --extendedDiagnostics output shows that most of the time goes to parsing or to a bloated file count, this option will not help much. Narrow the program first, as covered in the chapter on program scope.
The diagram shows where the option takes effect.
Measuring the effect
Do not turn the option on because a blog post said so. Measure it. Use the baseline command from the earlier chapter, once with the option off and once with it on. The --skipLibCheck flag on the command line overrides the config file, so you do not need to edit anything.
npx tsc --noEmit --extendedDiagnostics --skipLibCheck false | grep -E "Check time|Total time|Files"
npx tsc --noEmit --extendedDiagnostics --skipLibCheck true | grep -E "Check time|Total time|Files"Compare three lines:
Check timeshould drop. This is the number the option is meant to change.Total timeshows whether the saving matters for the whole run.Filesshould be identical in both runs. If it differs, something other than this option changed.
Run each command two or three times and compare the typical values, because the first run often pays for cold disk caches. A common result in a project with many @types packages is that check time falls by a noticeable fraction. In a small project with few dependencies, the difference may be too small to matter. In that case, leave the option at whatever your team prefers and look elsewhere.
A configuration that uses it
This is the same configuration from the topic's code examples. The skipLibCheck line is the one this chapter covers.
{
"compilerOptions": {
"noEmit": true,
"incremental": true,
"skipLibCheck": true,
"types": ["node"]
},
"include": ["src"]
}The types list and the include list reduce what enters the program. skipLibCheck reduces how much of that program is checked. They work together, and the effects add up.
What you give up
Errors inside .d.ts files stop being reported. Most of the time those errors are not yours to fix, but some of them describe real problems. Here is a small project that shows the effect. Create src/broken.d.ts:
declare const x: Missing;Then create src/index.ts:
const n: string = x;
console.log(n);The declaration file has no import or export, so x is a global. Now run the checker with the option off:
npx tsc --noEmit --skipLibCheck falseThe output reports the problem in the declaration file:
src/broken.d.ts(1,18): error TS2304: Cannot find name 'Missing'.With --skipLibCheck true, the command prints nothing and exits successfully. Notice what else happens: index.ts is fine either way. When a type cannot be resolved, the checker treats it as an error type that behaves like any. Your code that uses x compiles with no complaint, and the unsafe any flows into it silently.
This is the main risk. A missing type in a declaration file turns into any for every consumer. With skipLibCheck off, you would hear about it. With it on, you would not.
Other problems that the option hides:
- Conflicting declarations. Two packages that declare the same global with different types produce errors such as "Subsequent property declarations must have the same type" (TS2717) or "Duplicate identifier" (TS2300). These errors are reported inside the declaration files, so they disappear.
- Version mismatches. A package whose
.d.tsfiles need a newer TypeScript than you run, or a newer@types/nodethan you installed, can fail inside its own files. - Mistakes in generated declarations. If your build emits
.d.tsfiles, errors in them go unreported when the option is on.
Why it is usually acceptable
For application code, most .d.ts errors are outside your control. You cannot edit files in node_modules, and a dependency's internal type error rarely changes how your own code behaves. The TypeScript team's own performance guidance lists the option as a common and reasonable setting for this reason, and many project templates enable it by default.
The risk grows in two situations. The first is when you publish declaration files for others to consume. The second is when your project defines its own ambient declarations, such as files that augment global types. In both cases, errors in .d.ts files are errors you introduced.
A pattern that keeps both benefits
Keep the fast setting for daily work, and run the strict check on a schedule or in CI. Use a second config that extends the first and turns the option off:
{
"extends": "./tsconfig.json",
"compilerOptions": {
"skipLibCheck": false,
"incremental": false
}
}Save it as tsconfig.strict.json. Run it with:
npx tsc -p tsconfig.strict.jsonSetting incremental to false here keeps the slow, full check from sharing build state with the fast one. A nightly job or a dependency-upgrade pull request is a good place to run it. When that job fails, you learn about a declaration problem at a time you chose, instead of paying for the check on every save.
Interaction with other features
- Incremental builds. Changing
skipLibCheckchanges the compiler options recorded in.tsbuildinfo, so the next incremental run redoes the work. Flip it once, then measure on a second run. - Project references. Each project in a
tsc --buildgraph has its owntsconfig.json, so the option is set per project. A shared base config that sets it once keeps the projects consistent. - The
libfiles. The built-inlib.*.d.tsfiles are also.d.tsfiles, so they are skipped too. An older option namedskipDefaultLibCheckskipped only those.skipLibCheckcovers that case, so you do not need both. - Editor sessions. The language server reads the same option from your
tsconfig.json. If the editor feels slow on first load, a full check of declaration files is one possible cause, though the editor mostly checks the files you have open.
Decision criteria
Use this table when deciding.
| Situation | Suggested setting | Reason |
|---|---|---|
| Application with many `@types` packages | On | Saves check time, and `.d.ts` errors are rarely yours to fix |
| Library that ships its own `.d.ts` files | Off for the release check, on for daily work | Errors in your declarations affect every consumer |
| Project with your own ambient or augmenting declarations | On, plus a scheduled strict run | Fast edits, with a safety net for your own declarations |
| Check time is small in the baseline | Either | The saving is too small to matter, so choose for safety |
| Parse time or file count dominates | On, but fix scope first | The option does not change parse or bind work |
Common mistakes
- Treating it as a file filter. The option does not remove files. If
Filesstays high, fixinclude,exclude, ortypes. - Assuming only
node_modulesis skipped. Your own.d.tsfiles are skipped as well. - Enabling it without a baseline. Without before and after numbers, you cannot tell whether it helped or whether you only hid errors.
- Never running the strict check. A hidden error does not go away. It surfaces later as an unexpected
anyor a confusing type in a consumer. - Using it to silence an error you should fix. If the error is in a declaration you control, fix the declaration.
Summary of the working model
skipLibCheck removes the check pass over .d.ts files and leaves parsing, binding, and type resolution alone. It reduces Check time and nothing else. The cost is that errors inside declaration files, including your own, stop appearing, and unresolved types silently become any. Measure the saving with --extendedDiagnostics, and keep a strict configuration for CI so that hidden problems still surface somewhere.
Exercise
You run npx tsc --noEmit --extendedDiagnostics --skipLibCheck false and then the same command with --skipLibCheck true. The Check time line drops from 6.1s to 4.0s, but Parse time stays at 3.5s and Files is 4,200 in both runs. What did the option change and not change, and what would you investigate next for the remaining time?
Show answer
The option removed the checking of .d.ts files, which accounts for the 2.1s drop in check time. It did not change how many files are in the program or how long they take to parse. The 4,200 files and the 3.5s parse time suggest the program is too large. Next, use --listFilesOnly and --explainFiles to find files that were included by accident, and review include, exclude, and types.
Exercise
A declaration file in your project contains declare const config: Settings;, but the Settings type was renamed and no longer exists. With skipLibCheck on, tsc reports no errors and code using config compiles. Why, and how would you catch the problem without giving up the faster setting for daily work?
Show answer
The file is a .d.ts file, so its errors are not reported when skipLibCheck is on. The unresolved Settings becomes an error type that behaves like any, so every use of config compiles with no type safety. To catch it, add a tsconfig.strict.json that extends the main config and sets skipLibCheck to false, then run npx tsc -p tsconfig.strict.json in CI or on a schedule.