/**
* Returns the sum of all numbers passed to the function.
* @example
* sum([1,2,3])
* //returns 6
* sum(1,2,3)
* //returns 6
* @param {number[]|...number} params - ???
*/
function sum(params) {
var args = params instanceof Array ? params : arguments;
for (var i = 0, sum = 0; i < args.length; i++)
sum += args[i];
return sum;
}
'params'可以是数组或可重复的数字
但是“@param {number[]|...number}”不工作。
书面文档输出与“@param {number[]|number}”没有区别
表明这种情况的最佳方式是什么?
最佳答案
诀窍是使用括号。我在工作中使用了以下内容。
* @param {...(object|string)} col - An optional set of columns to select.
更新了您的参数名称,这应该有效:
* @param {...(number[]|number)} params - ???
我找不到括号的任何文档,但在 JSDoc 3.4.2 下可以解决问题。
这条评论:
/**
* Select columns manually.
* @param {...(object|string)} col - An optional set of columns to select.
* Each argument can either be a fully-qualified column name in the form
* <table-alias>.<column-name>, or an object with the following
* properties below. If no columns are specified, then all columns are
* selected.
* @param {string} col.column - The fully-qualified column name.
* @param {string} col.mapTo - The name of the property that the column
* should be mapped to in the resulting normalized object. @param
* @param {function} col.convert - A converter function that takes a single value
* from the database and transforms it. For example, a function that
* converts a bit from the database to a boolean value.
* @return {this}
*/
生成此文档:
希望对您有所帮助!
关于javascript - 如何用可重复的参数来表示多种类型的参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35692272/