question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JSDoc comment for destructuring param: description text not displayed

See original GitHub issue

TypeScript Version:
2.9

Search Terms:
JSDoc destructuring param

Code

/**
 * @param {Object} arg
 * @param {number} arg.id - This param description won't show up
 */
function foo({ id }) {}

Expected behavior: In VSCode 1.24.0, when typing foo(, IntelliSense should display the full param description, including its type and text.

Actual behavior: The type is displayed (“number”), but not the text (“This param description won’t show up”): image

Related Issues: https://github.com/Microsoft/TypeScript/issues/19645

Additional remark When omitting the {Object} line, the param text shows up correctly: image

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:23
  • Comments:14 (2 by maintainers)

github_iconTop GitHub Comments

11reactions
rbiggscommented, Sep 14, 2018

@THoisington, for that to work, you need to first define a custom object for the options, and then define its properties. Then you assign that custom type as your parameter:

/**
 * Entries Object.
 * @typedef {Object.<string, any>} requiredArguments
 * @property {string} timeSince
 * @property {string} timeUntil
 */
/**
 * 
 * @param {requiredArguments} param
 */
async function getEntries({timeSince, timeUntil}) {}

That’ll give you IntelliSense for each property on the options parameter.

10reactions
jnfraticommented, Jan 13, 2021

I’m having the same issue, I’m currently using javascript, and the solution provided by @lookuh partially implemented works in an awkward way.

When used the JSDocs comments in this way, it for sure won’t show the destructured params comments:

/**
 * @param {object} params
 * @param {stirng} params.id Some usefull id
 * @param {number} params.randomNumber Some randome number
 */

Captura de Pantalla 2021-01-13 a la(s) 11 33 41

But when at least one of the param is defined as property, it starts to show the other params comments correctly, but it does not give type to them:

Captura de Pantalla 2021-01-13 a la(s) 11 41 03

Captura de Pantalla 2021-01-13 a la(s) 11 42 56

And a full typedef with @property solution isn’t showing the destructured params:

/**
 * @typedef MyParams
 * @property {string} id Some usefull id
 * @property {number} randomNumber Some random number
 * @property {Date} someDate Just a date
 */


/**
 * @function useCustomHook
 * @param {MyParams} params
 */

Captura de Pantalla 2021-01-13 a la(s) 11 49 24

Hope this comment helps in any way.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JSDoc comments for destructuring parameters not working in ...
Param type is parsed correctly, allowing for type checking. Param description text doesn't show up in IntelliSense (issue reported here).
Read more >
Use JSDoc: @param
If a parameter is destructured without an explicit name, you can give the object an appropriate one and document its properties. Documenting a...
Read more >
Google JavaScript Style Guide
We do not use the phrase documentation comments , instead using the common term “JSDoc” for both human-readable text and machine-readable annotations within ......
Read more >
Refactoring JavaScript | WebStorm Documentation - JetBrains
Select the Search in comments and strings and Search for text ... default value in the JSDoc comment in the format @param <parameter...
Read more >
eslint-plugin-jsdoc - npm
settings.jsdoc.ignorePrivate - Disables all rules for the comment block on which a @private tag (or @access private ) occurs. Defaults to false ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found