Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Document collection (array of type) return value and parameter in JSDoc

How to document Array return value (and parameters) in JSDoc when array elements can be either of the following:

  • A type (e.g. String, Array).
  • An object literal.
like image 793
Jonathan Chan Avatar asked Dec 14 '11 02:12

Jonathan Chan


1 Answers

If you're looking for how to document the type of objects in an array, you want something like this:

/**  * @param {String[]} aliases  */ 

Here inside curly-braces the String[] is the parameter type: type String as array [].

See also jsdoc-toolkit, archived wiki page about @Param tag, Parameter Type Information:

Parameter Type Information

Use curly-braces around the expected type of the parameter to document this information.

/** * @param {String} userName */ function logIn(userName) { // ... }

Use a pipe symbol to document that multiple types are permitted.

/** * @param {String|Number} product */

Use the [] notation after a type to indicate an array of those types.

/** * @param {String[]} aliases */

like image 61
dmertl Avatar answered Oct 08 '22 01:10

dmertl