How to document overloaded functions in JS?
I have the following function. How do I properly document it so that IDEA's autocomplete understands that there are 2 variations of it? In both cases `opts` arg is the same. JSdoc generates a correct documentation for this code.
/**
* move to coords
*
* @param {number} x X coordinate
* @param {number} y Y coordinate
* @param {object} [opts] options
* @param {boolean} [opts.opt1] option 1
* @param {number} [opts.opt2] option 2
*//**
* move to point
*
* @param {object} target point struct
* @param {object} [opts] options
* @param {boolean} [opts.opt1] option 1
* @param {number} [opts.opt2] option 2
*/
function move(arg1, arg2, arg3) {
let x, y, opts;
if (typeof arg1 === "object") {
x = arg1.x;
y = arg1.y;
opts = arg2;
} else {
x = arg1;
y = arg2;
opts = arg3;
}
// do some stuff
}
move(1, 2, {opt1: true});
move({x: 1, y: 2}, {opt1: true});
Please sign in to leave a comment.
You are using the right way to document overloads, but it's not currently supported by IDEA:( please follow https://youtrack.jetbrains.com/issue/WEB-33414 for updates