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

Share:
12,775

Related videos on Youtube

doberkofler
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, 2020

Comments

  • doberkofler
    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 and value in jsdoc3 ?

  • Geza Kerecsenyi
    Geza Kerecsenyi over 4 years
    Is 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 @params (excluding the first, which becomes @typedef) to @type, @typedef and @param, but nothing seems to be working.
  • Felix Edelmann
    Felix Edelmann over 4 years
    I prefer using Array.<Object> over Object[], e.g. @param {Array.<Object>} filter. However, VSCode only recognized the array item's properties when using the Object[] syntax for the array. Is there a different method of specifiying array item properties when using Array.<Object>?