Javascript JSDoc中的文档重载函数
我有一个重载的toggle函数,希望用JSDoc记录行为 如果该值已定义,则窗口状态将设置为truthy参数的布尔值,如果未定义,则窗口状态将切换。我在找这样的东西Javascript JSDoc中的文档重载函数,javascript,jsdoc,Javascript,Jsdoc,我有一个重载的toggle函数,希望用JSDoc记录行为 如果该值已定义,则窗口状态将设置为truthy参数的布尔值,如果未定义,则窗口状态将切换。我在找这样的东西 /** * Set the map window in mobile * @param {undefined|*} on - toggle or set the window state * - {undefined} toggles window state * - {*} set window state */ t
/**
* Set the map window in mobile
* @param {undefined|*} on - toggle or set the window state
* - {undefined} toggles window state
* - {*} set window state
*/
toggleWindow(on) {
if (on === undefined) {
on = !this.state.window;
}
this.setState({ mapWindow: !!on });
}
摘自:
您需要将每个注释的开头和结尾放在一起,如下所示:
/**
* DateRange class to store ranges and query dates.
*
* @constructor
* @param {(Moment|Date)} start Start of interval
* @param {(Moment|Date)} end End of interval
*//**
* DateRange class to store ranges and query dates.
*
* @constructor
* @param {!Array} range Array containing start and end dates.
*//**
* DateRange class to store ranges and query dates.
*
* @constructor
* @param {!String} range String formatted as an IS0 8601 time interval
*/
function DateRange(start, end) {
// ...
}
但是,请注意,构造函数重载并没有分组在一起。每个重载仍然会收到完整的成员列表,因此部分文档变得多余。但是,在模板中可能是可修复的。因为前面的答案不适用于我。尝试:
/** @type {((param: string) => boolean) & ((param: string, overloadedParam: string) => string))} */
const func = (param, overloadedParam) => { … }
请将此答案归功于GitHub,可在此处找到:
(这适用于标准JS和TS)与您的实际问题无关,但如果您将
切换窗口
作为一个不带参数的函数,然后将其他功能移动到类似设置窗口
的位置,这似乎会更清楚。默认值@epascarelloon=!这个.state.window
不是一个坏主意,因为默认参数在“调用时间”重新计算,即使它没有直接回答问题,这样的回答应该会为您赢得一些选票。