Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you document an array of objects as a parameter in JSDoc?

I have an array that looks like this:

[{
    "name": "c917379",
    "email": "[email protected]"

},
{
    "name": "c917389",
    "email": "[email protected]"
}]

It is an array of arbitrary length with a number of repeating fields (I've reduced this to two fields for clarity). This gets passed into a JavaScript method.

/**
 * @param {?}  data
 */
update:  function(data) {...}

I was wondering how you would document this in JSDoc. Ie. how would you document the type where the question mark is?

like image 251
Oliver Watkins Avatar asked Jun 18 '13 08:06

Oliver Watkins


2 Answers

In JSDoc there is an example given for an array with members of type MyClass. It looks like this:

@param {Array.<MyClass>}

So then you can also do like this:

@param {Array.<Object>}

And then this also makes sense:

@param {Array.<{name:string, email:string}>}
like image 108
Wilt Avatar answered Oct 04 '22 03:10

Wilt


I just figured out the answer to my question :

It would look like this :

/**
 *
 * @param {{name:string, email:string}[]}  
 *
 */
like image 30
Oliver Watkins Avatar answered Oct 04 '22 02:10

Oliver Watkins