Skip to content

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

Description

@mjbvz

From Mike (@yo1dog) on March 15, 2018 20:10

  • 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.jsconstdoSomething=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 */functiondoSomething(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=functiondoSomething(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=functiondoSomething(inItem,cb){};
const doSomething: <string>(inItem: string, cb: (outItem: Buffer) => void) => void

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

Copied from original issue: microsoft/vscode#45909

Metadata

Metadata

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issueVS Code TrackedThere is a VS Code equivalent to this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions