How to document an array of objects in JSDOC
12,775
like this:
/**
* @param {Object[]} filter - a list of literal filter objects
* @param {string} filter[].id - id to filter against...
* @param {string|number} filter[].value - value to filter for...
*/
function doSomething(filter) {
// do stuff
}
taken from http://usejsdoc.org/tags-param.html
Related videos on Youtube
Author by
doberkofler
By-day: I am a managing partner in a software company and by-night I enjoy collaborating on open software. I'm especially interested in web development, testing and relational databases.
Updated on September 24, 2020Comments
-
doberkofler almost 4 years
I have a function with an array of objects as parameter and would like to describe the parameter (including the properties of the objects in the array) using JSDOC like in this example:
/** * @param {Array.<Object>} filter - array of filter objects * @param ... */ function doSomething(filter) { }
where filter is something like this:
filter = [ {id: 'session', value: 1}, {id: 'name', value: 'john'} ]
How would I document the properties
id
andvalue
in jsdoc3 ?-
Dan Dascalescu about 7 yearsPossible duplicate of Document collection (array of type) return value and parameter in JSDoc
-
-
Geza Kerecsenyi over 4 yearsIs there any way to use this with
@typedef
? I want to essentially do the exact same thing, except in an@typedef {Object[]} filter
instead of@param {Object[]} filter
, since I reuse the type a lot. I've tried the same thing but changing the@param
s (excluding the first, which becomes@typedef
) to@type
,@typedef
and@param
, but nothing seems to be working. -
Felix Edelmann over 4 yearsI prefer using
Array.<Object>
overObject[]
, e.g.@param {Array.<Object>} filter
. However, VSCode only recognized the array item's properties when using theObject[]
syntax for the array. Is there a different method of specifiying array item properties when usingArray.<Object>
?