简体   繁体   中英

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

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM