Skip to content

Incorrect name resolution for JSDoc template tag constraints in typedefΒ #45480

Closed
@rbuckton

Description

@rbuckton

Bug Report

πŸ”Ž Search Terms

jsdoc name resolve lookup symbol template constraint typedef

πŸ•— Version & Regression Information

  • This has been an issue since we added support for @template in JSDoc

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

/**
 * @template T
 * @template {keyof T} K
 * @typedef Foo
 */

πŸ™ Actual behavior

Reports Cannot find name `T`.

πŸ™‚ Expected behavior

Does not report an error.

Notes

Name resolution does not look at the symbol table of the @typedef tag, so when looking for T in the code below, we end up looking at T for the function declaration further down in this example:

/**
 * @template T
 * @template {keyof T} K
 * @typedef Foo
 */

/**
 * @template T
 * @param {T} a
 */
function bar(a) {
}

A "go-to-definition" on the T in keyof T jumps to the T declared for bar, not the T in the typedef for Foo.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: JSDocRelates to JSDoc parsing and type generation

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions