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.
The @type tag allows you to provide a type expression identifying the type of value that a symbol may contain, or the type of value returned by a function. You can also include type expressions with many other JSDoc tags, such as the @param tag.
The @param tag provides the name, type, and description of a function parameter. The @param tag requires you to specify the name of the parameter you are documenting. You can also include the parameter's type, enclosed in curly brackets, and a description of the parameter.
JSDoc comments are used for documentation lookup with Ctrl+Q in JavaScript and TypeScript, see JavaScript documentation look-up and TypeScript documentation look-up, as well as for type annotations and method return type hints in chained methods.
You can use most JSDoc type syntax and any TypeScript syntax, from the most basic like string to the most advanced, like conditional types.
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) {
// ...
};
/**
/**
* @typedef AwesomeObject
* @type {Object}
* @property {string} name
* @property {boolean} next
* @property {string} test
*/
/**
* @param {Array.<AwesomeObject>} awesomeObjects Awesome objects.
*/
myAwesomeFunction(awesomeObjects) { ... }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With