Open
Description
🔎 Search Terms
go to to definition, sub-packages, nested packages, declaration maps, sourcemap, monorepo
🕗 Version & Regression Information
- Project below is using
npm:@kitchensink/typescript-pr60005@latest
(Add source mappings for serialized properties with available declaration #60005) as it partially fixes the problem - Full tsconfig info: https://github.com/KATT/typescript-go-to-definition-through-sub-packages/blob/main/tooling/tsconfig/base.json
⏯ Playground Link
https://github.com/KATT/typescript-go-to-definition-through-sub-packages
💻 Code
TypeScript's "Go to Definition" goes to the wrong place when used through multiple levels of package imports. Here's the setup:
-
Package
@org/a
defines a base object:export const a = { foo: 'foo', bar: 'bar', baz: 'baz', qux: 'qux', } as const;
-
Package
@org/b
imports and re-exports package@org/a
's object:import { a } from '@org/a'; a; // ✅ Go to definition works here with ^5.7.3 a.foo; // 🚧 Go to definition does not work here, but seemingly fixed by https://github.com/microsoft/TypeScript/pull/60005 export const b = { a, } as const;
-
Package
@org/c
imports from package@org/b
and tries to access the nested property:import { b } from '@org/b'; b; // 🚧 Go to definition does not work here, but seemingly fixed by https://github.com/microsoft/TypeScript/pull/60005 b.a; // <--- 🚧 Go to definition does not work here, but seemingly fixed by https://github.com/microsoft/TypeScript/pull/60005 b.a.foo; // <--- ❌ ❌ Go to definition on ".foo" should go to `a.foo` in `@org/a`, but instead goes to end of file in `@org/b`
🙁 Actual behavior
- In package
@org/b
, TypeScript's "Go to Definition" works as expected when clicking ona.foo
if using branch Add source mappings for serialized properties with available declaration #60005 - In package
@org/c
, "Go to Definition" does not work as expected when trying to navigate through the re-exported propertyb.a.foo
- it goes to end of file of@org/b
instead of the wherefoo
is declared in@org/a
🙂 Expected behavior
Go to definition should work through multiple levels of package imports as if the code was written in a single file.
Additional information about the issue
Partially addressed by #60005, I'm using npm:@kitchensink/typescript-pr60005@latest
in the repo