Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to describe destructured object arguments in JSDoc

If I have a JavaScript function taking an object as a parameter, I can describe expected properties of the object with JSDoc like this:

/**
 * @param bar
 * @param bar.baz {number}
 * @param bar.qux {number}
 */
function foo(bar) {
    return bar.baz + bar.qux;
}

How do I describe these properties if I define my function with ECMAScript 6 destructuring, not giving the real parameter object a name at all?

const foo = ({ baz, qux }) => baz + qux;
like image 500
Henrik Avatar asked Jun 20 '17 05:06

Henrik


People also ask

How do you document an object in Jsdoc?

If a parameter is expected to have a specific property, you can document that property by providing an additional @param tag. For example, if an employee parameter is expected to have name and department properties, you can document it as follows: /** * Assign the project to a list of employees.

What is the Jsdoc keyword to specify an argument to a function?

The @param tag provides the name, type, and description of a function parameter.

What does Param mean in Javascript?

A parameter is a named variable passed into a function. Parameter variables are used to import arguments into functions. For example: function example(parameter) { console.


1 Answers

It turns out JSDoc does support destructing via making up a placeholder name. It is lacking in official documentation.

http://usejsdoc.org/tags-param.html#parameters-with-properties

/**
 * @param {Object} param - this is object param
 * @param {number} param.baz - this is property param
 * @param {number} param.qux - this is property param
 */
const foo = ({ baz, qux }) => baz + qux;
like image 196
Peter Kota Avatar answered Oct 08 '22 03:10

Peter Kota