JSDoc on an object's properties to describe params of a function

1.4k views Asked by At

If I have an object (or more precisely an object assigned to module.exports in node) and this object's properties may consist of functions, how do I document the parameters and return value of the function?

Example:

module.exports = {
    /**
     * Adds two numbers together.
     * @param {number} first The first number
     * @param {number} second The second number
     * @return {number} The sum of the two numbers
    */
    "add": function(first, second) {
        return first + second;
    }
}

This doesn't seem to be supported (at least not in VSCode) and I couldn't find anywhere in JSDoc docs that describe a way to document the arguments of the function in this scenario (or just for a plain object). The JSDoc description works (it is displayed by VSCode's Intellisense), but the param definitions and return definition is not.

Is there a way to document functions so they show up in objects that reference them?

1

There are 1 answers

1
David Murdoch On

This actually works correctly in VSCode. My problem was that my @param types didn't have proper capitalization (Object works while object does not) which means Intellisense won't work. Note: Number and number are both fine, and I suspect there are other "types" that also don't care about case sensitivity.