描述JSDoc中的对象数组

Describing an array of objects in JSDoc

本文关键字:对象 数组 JSDoc 描述      更新时间:2023-09-26

我有一个函数,它接受一个对象数组。
是这样的

myAwesomeFunction([
    {
        name: 'someName',
        next: false,
        test: 'test'
    },
    {
        name: 'nameTwo',
        next: true
    }
]);
到目前为止,我的JSDoc看起来像这样
/**
 * My description
 * @param {Array.<Object>}
 */

但是我如何描述对象的属性、类型和描述,以及它们是否为对象的可选?

谢谢。

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) {
    // ...
};
/**

Using typepedef

/**
 * @typedef AwesomeObject
 * @type {Object}
 * @property {string} name
 * @property {boolean} next
 * @property {string} test
 */
/**
 * @param {Array.<AwesomeObject>} awesomeObjects Awesome objects.
 */
myAwesomeFunction(awesomeObjects) { ... }