TypeScript refuses to compile when a triple-slash `types` directive appears inside a file but the compiler is still checking library declaration files. The directive is only permitted when `skipLibCheck` is turned on, so the fix is either to drop the directive or to let the compiler skip library checking
Fixes Triple-slash directive 'types' requires 'skipLibCheck'
{
"compilerOptions": {
"types": ["node", "jest"]
}
}{"compilerOptions": {"types": ["node", "jest"]}}Triple-slash directive 'types' requires 'skipLibCheck'
A `/// <reference types="..." />` directive declares that the current file depends on another declaration package (usually an `@types` package). These directives were invented for legacy scripts, not modern modules, so the compiler only honors them when it skips type checking for library files. Turning on `skipLibCheck` tells TypeScript to trust the ambient declarations it already loaded from `node_modules`, which is the same context that the triple-slash directive expects. Without `skipLibCheck`, the compiler would try to re-verify every referenced declaration and the directive creates conflicting ordering assumptions, so it halts with "Triple-slash directive 'types' requires 'skipLibCheck'".
Triple-slash types directives work like declarative imports for ambient packages. Instead of editing the file, list the package under "compilerOptions.types" (or adjust "typeRoots") in tsconfig. Example:
{
"compilerOptions": {
"types": ["node", "jest"]
}
}Now the compiler loads those ambient modules automatically and the error disappears, because the file no longer contains a /// <reference types="..." /> comment that demands skipLibCheck.
If a third-party declaration file or a generated .d.ts still uses /// <reference types=... />, the only supported path is to allow TypeScript to skip library checking. Add or flip this option in tsconfig:
{
"compilerOptions": {
"skipLibCheck": true
}
}skipLibCheck tells the compiler to skip verifying every .d.ts file inside node_modules, which is exactly what TypeScript expects before honoring the extra triple-slash reference. Run npx tsc --project tsconfig.json afterwards to confirm the diagnostic disappears.
Because skipLibCheck weakens guarantees, some teams only enable it during declaration generation or when bundling. Create a secondary config for that phase:
// tsconfig.build.json
{
"extends": "./tsconfig.json",
"compilerOptions": {
"skipLibCheck": true,
"declaration": true,
"outDir": "./dist"
}
}Use tsc --project tsconfig.build.json for publishing, while day-to-day development still runs tsc --project tsconfig.json with skipLibCheck disabled. This way, triple-slash types from dependencies stay compatible without letting the main build miss real library errors.