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
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.
Function expression requires a return type
Function expression requires a return type
Value of type 'string | undefined' is not iterable
How to fix "Value is not iterable" in TypeScript
Type 'undefined' is not assignable to type 'string'
How to fix "Type undefined is not assignable to type string" in TypeScript
Type narrowing from typeof check produces 'never'
How to fix "Type narrowing produces never" in TypeScript
Type parameter 'T' has conflicting constraints
How to fix "Type parameter has conflicting constraints" in TypeScript