Sub topic 4
Skipping Declaration File Checks with `skipLibCheck`
Assume you are comfortable with TypeScript interfaces, generics, union types, tsconfig.json, and running tsc with npx. This chapter focuses on one targeted optimization: reducing checking time spent in declaration files.
What `skipLibCheck` changes
A declaration file is a file ending in .d.ts. It describes types without containing the implementation. TypeScript uses declaration files for the standard library, installed packages, and your own published type declarations.
When skipLibCheck is true, TypeScript skips full type checking of declaration files. It still reads their declarations and uses them to check your .ts files. Your application code is still checked normally.
{
"compilerOptions": {
"noEmit": true,
"strict": true,
"skipLibCheck": true
},
"include": ["src"]
}This option often helps when a project loads many large libraries or when several packages contain incompatible versions of the same type. It mainly reduces checking work. It does not prevent TypeScript from finding declaration files, parsing them, or using their exported types.
The relationship looks like this:
Measure the effect
First record a baseline. Run the same command before and after changing the option.
npx tsc --noEmit --extendedDiagnosticsLook at Check time, Files, and Types. skipLibCheck usually affects Check time, but the result depends on how many declaration files your program includes and how complex they are.
For a clearer comparison:
- Run the command with the current configuration.
- Record the total time and check time.
- Set
"skipLibCheck": true. - Run the command again.
- Compare the numbers.
Do not compare a cold run with a warm run without noting the difference. Operating-system caches and incremental state can affect timings.
What it skips and what it does not
| Setting | Declaration files | Your `.ts` files | Typical result |
|---|---|---|---|
| `skipLibCheck: false` | Fully checked | Fully checked | More diagnostics and potentially longer checks |
| `skipLibCheck: true` | Not fully checked | Fully checked | Faster checks with less validation of declarations |
The option does not fix a bad dependency or remove a type package from the program. It also does not make complex types in your own .ts files cheaper to evaluate.
A declaration error may disappear after enabling the option. For example, two packages might declare the same global interface differently. That can make the build pass, but it can also hide a real incompatibility. Your code may then be checked against a merged or otherwise unexpected type.
When to use it
skipLibCheck is a reasonable default for many applications when:
- Dependencies provide the declarations you consume.
- The project does not publish those declarations as a library.
- Declaration checking takes a noticeable part of the build.
- Dependency conflicts are understood or accepted.
Be more cautious when developing a library, maintaining shared type declarations, or upgrading dependencies. A library's declaration output is part of its public API. Full checking can catch errors before consumers encounter them.
If enabling the option removes errors, inspect the errors before accepting the change. Upgrade or deduplicate conflicting packages when that is the real cause. Then rerun diagnostics to confirm that the speed improvement is meaningful.
Verify the change
Keep the configuration change small and measure it. A successful optimization should reduce the relevant time without changing application diagnostics. Run your normal type-check command and your test suite after the change. If declaration errors must remain visible in CI, you can use different configurations for fast local checks and stricter validation.
Exercise
Your baseline reports 18 seconds of check time, and most included files are dependency .d.ts files. After setting "skipLibCheck": true, check time falls to 9 seconds, but a conflicting dependency error disappears. What should you do before keeping the setting?
Show answer
Inspect the dependency conflict and decide whether it represents a real compatibility problem. Upgrade, deduplicate, or align the packages if possible. Keep skipLibCheck only if hiding that declaration error is an acceptable, documented trade-off.