JSDoc Passing Array of Objects Notation

Version: 6.1.3 - build 1424

How do you JSDoc annotate a method whose only parameter is an array of Objects?

I use the following JSDoc line:

@param {Array<Object>} a An array of Objects

which seems to satisfy the JSDoc parser, but when referencing Object members, the following warning is emitted:

The property member_name is undefined for the Javascript type Object.

Meta-code that emits the error:

for ( var i = 0; i < a.length; i++ )
{
    var o = a[ i ]
        
    var x = o.member_name

    <more code>
}

I tried various permutations of the Object double-braces notation in the @param line of code, but the JSDoc parser complains:

{{ member_1 : String, member_2 : Number, member_3 : Boolean }}

By the way, the method’s code works as expected…it’s just the JSDoc warnings that I cannot seem to clear.

EDIT: Never mind…I figured it out. Keep the JSDoc @param as is and add @type with the double-braces detail to the declared Object in the code.

Hi Kim,

yes, using @type is a solution.

this is what you were looking for:

@param {Array<{member_name:String, member_id:Number}>} myVarName

Thanks for the assist, Marc! I prefer your annotation and changed mine accordingly.