CORE JSC

International Technology Partnership

VS Code / Tools

Fixing VS Code's Go to Definition That Jumps to a .d.ts File Instead of the Real TypeScript Source

Go to Definition on a function from a monorepo package or a locally-linked library lands on an auto-generated .d.ts declaration file in a dist or build folder — a file with no implementation, no comments, and nothing useful to actually read or edit — instead of the real TypeScript source it was compiled from. The type information is correct; what's missing is the map that lets VS Code trace the declaration back to where it actually came from.

Core JSC Team·November 26, 2026
VS CodeTypeScriptMonorepoDeveloper ToolsIntelliSense

The Problem

Ctrl-clicking (or using "Go to Definition") on a function imported from a sibling package in a monorepo, or from a library linked locally via a workspace setup, lands on a generated .d.ts file inside that package's dist/ or build/ output — a file containing nothing but type signatures, with no function body, no inline comments, and no way to actually see or edit the logic behind the function. The real implementation lives in a .ts file in that package's own src/ directory, but navigating there requires manually opening the file rather than following the jump VS Code was supposed to provide.

Why It Happens

A package's published or built output is what TypeScript actually resolves against, and by default that's the compiled .d.ts, not the original source

When one package imports another, TypeScript resolves the import against whatever that package's package.json types (or main) field points to — typically a .d.ts file in a build output directory. This is correct and necessary for type-checking: the consuming package only needs the type declarations, not the original source. But it means "Go to Definition" is, by default, jumping to exactly the file TypeScript actually used for type resolution, which is the .d.ts, not the .ts file that produced it.

Without a declaration map, there's no recorded link between the .d.ts file and the original source line it was generated from

TypeScript can optionally emit a .d.ts.map file alongside each .d.ts — a declaration map, conceptually similar to a JavaScript source map — that records exactly which line of the original .ts source each part of the generated declaration came from. Without this map being generated (it's off by default), there's no information anywhere for an editor to use to trace a .d.ts declaration back to its real source, even though the two files are directly related.

VS Code only follows a declaration map to the real source when the package's build output actually includes one and the editor is configured to prefer it

Even with declaration maps being generated, VS Code's TypeScript language service needs to actually find and trust the .d.ts.map file sitting next to the .d.ts it's looking at, and in some versions and configurations a setting controlling whether source-level navigation is preferred over the compiled output needs to be explicitly enabled — the map being present and the editor correctly using it are two separate things that both have to be true.

The Fix

1. Enable declarationMap (alongside declaration and sourceMap) in the source package's tsconfig.json

// The package being imported FROM (e.g. packages/shared-utils/tsconfig.json)
{
  "compilerOptions": {
    "declaration": true,
    "declarationMap": true,
    "sourceMap": true
  }
}

This is the essential, non-optional first step — without declarationMap specifically, no amount of editor configuration can make "Go to Definition" trace back to real source, because the information needed to do so simply doesn't exist in the build output yet.

2. Rebuild the source package so the new .d.ts.map files are actually generated and present in its output

cd packages/shared-utils
npm run build
# Confirm the .d.ts.map files now exist alongside the .d.ts files:
ls dist/*.d.ts.map

A tsconfig.json change alone does nothing until the package is actually rebuilt — a stale build from before the declarationMap setting was added will still be missing the map files, so this step has to happen and be verified, not just assumed from the config change.

3. Ensure the consuming project's own TypeScript configuration doesn't disable source-level navigation

// settings.json
{
  "typescript.preferGoToSourceDefinition": true
}

Some VS Code/TypeScript versions expose an explicit setting controlling whether "Go to Definition" prefers the real source (when a declaration map makes that possible) over the .d.ts it's directly resolving against — checking this setting is enabled closes the gap for cases where the map exists but the editor still defaults to the compiled file.

4. For a monorepo using TypeScript project references, confirm the referenced project's build is actually up to date relative to its source

npx tsc --build --force
# Forces a fresh build across all referenced projects, ensuring
# the .d.ts and .d.ts.map files reflect the current source rather
# than a stale build from before a recent source change.

In a project-references setup, an out-of-date referenced project's build output can point a declaration map at source lines that have since shifted or changed — forcing a fresh build across the whole reference graph removes this as a possible cause before concluding the declaration-map setup itself is wrong.

Why This Works

Landing on a .d.ts file isn't a sign "Go to Definition" is broken — it's correctly showing exactly what TypeScript resolved the import against, which by default is the compiled declaration rather than the original source. Declaration maps are the specific mechanism that lets an editor bridge that gap, and they have to actually be generated, present in a fresh build, and correctly used by the editor's settings — missing any one of those three steps leaves the jump landing on the compiled file exactly as before.

Conclusion

"Go to Definition" landing on a compiled .d.ts file instead of the real TypeScript source is a missing declaration map, not a broken navigation feature. Enabling declarationMap in the source package's tsconfig, rebuilding so the map files actually exist, confirming the editor's source-preference setting, and forcing a fresh build in a project-references setup together turn a dead-end jump into one that lands exactly where the real implementation lives.