Search code examples
javascriptjavadocphpstorm

Is there a JavaDoc annotation that defines a function argument as a callback?


Is there a javadoc way to tell PHPStorm that a Javascript function accepts a callback as a parameter?

/**
 * Calculates the and calls the callback function.
 *
 * @param {string} arg1 The argument.
 * @param {????} callback A function to be called.
 **/
foo: function(arg1,callback)
{
   //...
   callback();
}

Solution

  • you can use {function} type for this, like

    /** 
     * @param {function(number):string} f 
     * @param {number} n 
     * @return {string} 
    */
    function foo( f, n ){  return f(n); }
    

    See Google Closure compiler docs, 'Type Expressions' section for more info

    JSDoc 3 also introduces a @callback tag (http://usejsdoc.org/tags-callback.html), but it's not yet supported (see this issue)