11

How do I format nested arrays and objects using jsdoc?

This is my best guess:

an_obj = { 
        username1 : [
            {
                param1 : "value 1-1-1",
                param2 : "value 1-1-2",
                optional_nested : "1-1--2"
            },
            {
                param1 : "value 1-2-1",
                param2 : "value 1-2-2"
            },
        ],
        username2 : [
            {
                param1 : "value 2-1-1",
                param2 : "value 2-1-2"
            },
            {
                param1 : "value 2-2-1",
                param2 : "value 2-2-2",
                optional_nested : "2-2--2"              

            }
        ]
    }
}


/**
 * A function description.
 * @param {Object} obj
 * @param {Object} obj.username  This is not the object name, but a name type. 
 * @param {Array}  obj.username.array Desc...  using [] would conflict with optional params.
 *                                    However this could be confused with an object called array.
 * @param {String} obj.username.array.param1 Desc... This is the object name rather than a type.
 * @param {String} obj.username.array.param2 Desc... 
 * @param {String} obj.username.array.[optional_param] Desc... 
 */
var myFunc = function(obj){
    //...
};
myFunc(an_obj);

How do I indicate that an object is indexed by a kind of string?

How do I define a nested array?

Also not sure where to put the square brackets in the optional parameter.

2 Answers 2

1

You can try doing it like this : (as specified here http://code.google.com/p/jsdoc-toolkit/wiki/TagParam)

/**
* @param {String[]} obj.username.array
*/

This is supposed to declare obj.username.array as an array of strings. Are you using jsdoc or jsdoc3?

Sign up to request clarification or add additional context in comments.

2 Comments

I'm currently using jsdoc-toolkit v3. I can't figure out how to deal with something like this {id: 'moo', items: [{url: '...',description: 'moo2'},...]}
This doesn't help, the case is documenting arrays of anonymous objects, not arrays of real objects
1

I'd recommend checking this out. I'd probably write it something like this:

//{Object{username:<Array<Object{param1:String, param2:String,[optional_nest]:string}>>}}

1 Comment

Link is dead and the above example throws "Invalid type expression" with jsdoc 3.3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.