How to document deconstructed parameters with JsDoc
Asked Answered
M

1

16

How do I document a function parameter that gets deconstructed in function arguments?

/**
 * Function deconstructs argument and do stuff.
 * @param {} *** what should i do here? ***
 */
function someFunction({ key1, key2, key3 }) {
    // do function stuffs
}
Moynihan answered 21/8, 2017 at 2:29 Comment(2)
Does this answer your question? Document destructured function parameter in JSDocJewelry
Yes, it does, thank you @AncientSwordRage. will close this as a duplicate.Moynihan
H
27

From the @param wiki page:

If a parameter is destructured without an explicit name, you can give the object an appropriate one and document its properties.

Documenting a destructuring parameter

/**
 * Assign the project to an employee.
 * @param {Object} employee - The employee who is responsible for the project.
 * @param {string} employee.name - The name of the employee.
 * @param {string} employee.department - The employee's department.
 */
Project.prototype.assign = function({ name, department }) {
    // ...
};
Hampstead answered 21/8, 2017 at 2:29 Comment(2)
How do you document function (arg1, arg2, { prop1, prop2 })?Alkyne
You add @param tags for arg1 and arg2 before the one for the third argument.Hampstead

© 2022 - 2024 — McMap. All rights reserved.