Is there a proper syntax for documenting optional JavaScript parameters, where the optional parameter comes in the middle of the function header (think jQuery, Gulp, etc.)
I've documented the function in the standard way and that works fine. The catch is when I try to set the second parameter to last variable (in the case where the optional parameter wasn't used), my IDE gets confused.
Example:
/**
* @param {number} a_num
* @param {string} [a_str='']
* @param {{}} a_obj
*/
function (a_num, a_str, a_obj) {
if (!a_obj) a_obj = a_str; // doesn't want me to save a string to an object.
a_str = '';
// more stuff
}
If it matters, I'm using PHPStorm by JetBrains, which uses the Google Closure style of docs (mainly). Though I'm looking for a more general, best practice approach.
I suspect I could do something ugly like:
/**
* @param {number} a_num
* @param {string|{}} a_str
* @param {{}} [a_obj=null]
*/
But that doesn't really describe the situation as accurately as I'd like. I'm hoping since this is becoming a common structure that there is something to handle it properly.