Skip to content

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

@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