javascriptjsdoc

Make JSDoc comment for function which takes another function as parameter


Imagine a function which accepts an "onUpdate" function as a parameter:

 /**
 * @param {function} onUpdate
 * @returns {null}
 */
static async init(onUpdate) {
    ...
    onUpdate(true);
};

onUpdate takes a boolean as an argument. I want to add that arguments to @param {function} onUpdate.

Is there a way?

Some magnificent devs managed to do it on these addEventListener functions:


Solution

  • I think in screenshot you see typescript hint. But you can do something like this:

    /**
     * This callback is displayed as a global member.
     * @callback someCallback
     * @param {number} param1
     * @param {number} param2
     * @returns {number}
     */
    
    /**
     * 
     * @param {someCallback} cb 
     */
    
    function someFunction(cb) {
    
    }
    

    And see this hint