Skip to content

Go to definition through sub-packages #61001

Open
@KATT

Description

@KATT

🔎 Search Terms

go to to definition, sub-packages, nested packages, declaration maps, sourcemap, monorepo

🕗 Version & Regression Information

⏯ 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:

  1. Package @org/a defines a base object:

    export const a = {
    	foo: 'foo',
    	bar: 'bar',
    	baz: 'baz',
    	qux: 'qux',
    } as const;
  2. 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;
  3. 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 on a.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 property b.a.foo - it goes to end of file of @org/b instead of the where foo 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions