Skip to main content

require-declaration-map

Require "declarationMap": true in compilerOptions when "declaration": true is explicitly present.

Targeted pattern scopeโ€‹

The compilerOptions.declaration and compilerOptions.declarationMap fields in any tsconfig*.json file.

What this rule reportsโ€‹

This rule reports when compilerOptions is present, compilerOptions.declaration is explicitly true, but compilerOptions.declarationMap is absent or set to false. The rule does not report if compilerOptions is not defined at all.

Why this rule existsโ€‹

When a TypeScript library emits declaration files, editors and other tools use those .d.ts files for type information. Without a declaration map, "go to definition" jumps to generated .d.ts output instead of the original TypeScript source.

With declarationMap: true, TypeScript emits a .d.ts.map file alongside each .d.ts file so tools can navigate back to the original source.

The auto-fixer adds "declarationMap": true to compilerOptions.

โŒ Incorrectโ€‹

{
"compilerOptions": {
"declaration": true,
"outDir": "./dist"
}
}
{
"compilerOptions": {
"declaration": true,
"declarationMap": false,
"outDir": "./dist"
}
}

โœ… Correctโ€‹

{
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"outDir": "./dist"
}
}

Behavior and migration notesโ€‹

  • declarationMap: true only takes effect when declaration: true is also set. When declaration is absent or false, this rule does not report.
  • The generated .d.ts.map files must be published alongside .d.ts files for consuming projects to benefit. Add the *.d.ts.map glob to the files or exports entries in package.json.
  • This rule currently checks only the explicit declaration: true setting in the same config.

When not to use itโ€‹

Disable this rule for configs that intentionally omit declaration maps โ€” for example, internal monorepo packages where source is always available locally, or build configs that skip declaration output entirely.

Package documentationโ€‹

Rule catalog ID: R037

Further readingโ€‹