[英]How to document inconsistent returns with JSDoc?
Is it possible to add @return
JSDoc annotation for a function with inconsistent returns? 是否可以为
@return
不一致的函数添加@return
JSDoc注释?
/**
* @param {Number} a
* @param {Number} b
* @return {Number}
* */
function sum (a, b) {
if (a < b) return false; //here we have a Boolean
return a + b; //and here a Number
}
Note: 注意:
There's an example right there in the JSDoc @returns
documentation : JSDoc
@returns
文档中有一个示例:
The return value can have different types
返回值可以有不同的类型
/** * Returns the sum of a and b * @param {Number} a * @param {Number} b * @param {Boolean} retArr If set to true, the function will return an array * @returns {Number|Array} Sum of a and b or an array that contains a, b and the sum of a and b. */ function sum(a, b, retArr) { if (retArr) { return [a, b, a + b]; } return a + b; }
Eg, use |
例如,使用
|
, as you do other times the type may vary. ,就像您其他时候一样,类型可能会有所不同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.