Skip to content

JSDocs @template does not work as expected on export #45909

@yo1dog

Description

@yo1dog
  • VSCode Version: 1.21.1
  • OS Version: 10.10.5

When using JSDocs to describe a function using @template, Intellisence does not correctly infer the template type if the template type is used in a parameter in a function parameter description and is exported on the same line it is declared. Difficult to describe. See the cases bellow.

In the cases bellow, I will give the content of doSomething.js and the Intellisence output when hovering over doSomething(...) in the following code:

// otherFile.js
const doSomething = require('./doSomething');

doSomething('hello', (outItem => {}));

Case 1

Declaring the function then exporting after.

// doSomething.js
/**
 * @template T
 * @param {T} inItem
 * @param {(outItem:T) => void} cb
 */
function doSomething(inItem, cb) {
}

module.exports = doSomething;
const doSomething: <string>(inItem: string, cb: (outItem: string) => void) => void

Works as expected. Intellisence knows the template type is string.

Case 2

Declaring the function and exporting on the same line.

// doSomething.js
/**
 * @template T
 * @param {T} inItem
 * @param {(outItem:T) => void} cb
 */
module.exports = function doSomething(inItem, cb) {
};
const doSomething: <T>(inItem: T, cb: (outItem: T) => void) => void

Does not work as expected. Expected the same result as Case 1.

Case 3

Declaring the function and exporting on the same line, but not referencing T in the callback.

// doSomething.js
/**
 * @template T
 * @param {T} inItem
 * @param {(outItem:Buffer) => void} cb
 */
module.exports = function doSomething(inItem, cb) {
};
const doSomething: <string>(inItem: string, cb: (outItem: Buffer) => void) => void

Works as expected. Intellisence knows the template type is string.

Metadata

Metadata

Assignees

Labels

bugIssue identified by VS Code Team member as probable bugjavascriptJavaScript support issuesupstreamIssue identified as 'upstream' component related (exists outside of VS Code)verifiedVerification succeeded

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions