9

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.

Yves M.
  • 26,153
  • 20
  • 93
  • 125
Per Pettersen
  • 101
  • 1
  • 3
  • 2
    Exact duplicate of [Document collection (array of type) return value and parameter in JSDoc](https://stackoverflow.com/questions/8498975/document-collection-array-of-type-return-value-and-parameter-in-jsdoc) – Dan Dascalescu Jun 12 '17 at 05:12

2 Answers2

24

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) {
    // ...
};
/**
Danil Gudz
  • 1,884
  • 11
  • 16
9

Using typedef

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

/**
 * @param {Array.<AwesomeObject>} awesomeObjects Awesome objects.
 */
myAwesomeFunction(awesomeObjects) { ... }
Yves M.
  • 26,153
  • 20
  • 93
  • 125