Describing an array of objects in JSDoc
Asked Answered
B

2

16

I've got a function which takes an array of objects.
Looks like this.

myAwesomeFunction([
    {
        name: 'someName',
        next: false,
        test: 'test'
    },
    {
        name: 'nameTwo',
        next: true
    }
]);

So far my JSDoc looks like this

/**
 * My description
 * @param {Array.<Object>}
 */

But how can I describe the object properties, types and descriptions and if they are optional of the object?

Thank you.

Belter answered 9/10, 2016 at 11:7 Comment(1)
Exact duplicate of Document collection (array of type) return value and parameter in JSDocJonijonie
A
42

JSDoc @param documentation

/**
 * Assign the project to a list of employees.
 * @param {Object[]} employees - The employees who are responsible for the project.
 * @param {string} employees[].name - The name of an employee.
 * @param {string} employees[].department - The employee's department.
 */
Project.prototype.assign = function(employees) {
    // ...
};
/**
Astronomical answered 9/10, 2016 at 11:17 Comment(1)
Updated link: jsdoc.app/tags-param.htmlDenominate
S
16

Using typedef

/**
 * @typedef AwesomeObject
 * @type {Object}
 * @property {string} name
 * @property {boolean} next
 * @property {string} test
 */

/**
 * @param {Array.<AwesomeObject>} awesomeObjects Awesome objects.
 */
myAwesomeFunction(awesomeObjects) { ... }
Samba answered 21/11, 2016 at 14:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.