Course contentsShow
← TypeScript
Lesson 1249 of 1,79629. The Build PipelineFree lesson

Declaration Maps for Source Navigation

Enable declarationMap to let editors jump from .d.ts files back to original TypeScript source.

Declaration Maps for Source Navigation

What you'll learn: How to enable declaration maps so your editor can jump from compiled .d.ts declaration files back to the original TypeScript source.

What Are Declaration Maps?

When you publish a TypeScript library with declaration: true, the compiler generates .d.ts files that describe your API's types. By default, when someone imports your library and clicks "Go to Definition" in their editor, they land in these .d.ts files—not your original, readable .ts source.

Declaration maps create a bridge back to the source. They're like source maps for types: a .d.ts.map file that tells editors where each type declaration originally came from.

Why This Matters

Imagine you're debugging a third-party library. You want to see the actual implementation, not just type signatures. With declaration maps enabled, your IDE can navigate you to the original TypeScript source files (if the library includes them), making it much easier to understand complex types, read inline comments, and trace logic.

Enabling Declaration Maps

Set declarationMap: true in your tsconfig.json:

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

This generates .d.ts.map files alongside your .d.ts files. When you publish your package with both the declarations and the original .ts source files included, consumers get seamless source navigation.

The Library Author's Workflow

If you're building a library, include your src folder in the published package so users can navigate to it. Without the original source, the map has nothing to point to.

Key Takeaway: Enable declarationMap: true to generate .d.ts.map files that let editors jump from type declarations back to your original TypeScript source, vastly improving the debugging and exploration experience for library consumers.