Several additional JSDoc options

I have a function from js with the following signature:

  function foo(name, opt_callback, opt_dataStr);

      

And I'm trying to annotate this with JSDoc for the Closure compiler like this:

 /**
  * @param {string} name
  * @param {function(*)=} opt_callback
  * @param {string=} opt_dataStr
  */

      

But the compiler generates a dozen type warnings every time opt_callback is not passed and opt_dataStr, complaining that I am passing a string where I should have a function. I'm sure there is a simple solution on how to annotate this correctly, but I've tried

 * @param {function(*)=|string=} opt_callback

      

and

 * @param {(function(*)|string)=} opt_callback

      

etc., to no avail. Can anyone point me in the right direction?

+3


source to share


1 answer


Recent works, this is compilation without warning:

/**
  * @param {string} name
  * @param {(function(*)|string)=} opt_callback
  * @param {string=} opt_dataStr
  */
function fn(name, opt_callback, opt_dataStr) {}

fn('a','b');

      



Here's an example

0


source







All Articles