¿Cómo indicar que param es opcional usando JSDoc en línea?
De acuerdo con el wiki de JSDoc para @param puede indicar que un @param es opcional usando
/**
@param {String} [name]
*/
function getPerson(name) {
}
Y puede indicar un parámetro inline usando
function getPerson(/**String*/ name) {
}
Y puedo combinarlos como el siguiente, que funciona bien.
/**
@param [name]
*/
function getPerson(/**String*/name) {
}
Pero me gustaría saber si hay una manera de hacerlo todo en línea si es posible.
69
3 answers
Parámetro opcional
Un parámetro opcional llamado foo.
@param {number} [foo]
// or:
@param {number=} foo
Un parámetro opcional foo con el valor predeterminado 1.
@param {number} [foo=1]
52
Author: czerny,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-04-04 00:39:51
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-04-04 00:39:51
Después de algunas excavaciones encontré que estos también están bien
/**
* @param {MyClass|undefined}
* @param {MyClass=}
* @param {String} [accessLevel="author"] The user accessLevel is optional.
* @param {String} [accessLevel] The user accessLevel is optional.
*/
Solo un poco más atractivo visualmente que function test(/**String=*/arg) {}
50
Author: vvMINOvv,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-04-19 01:07:51
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-04-19 01:07:51
Encontré una manera de hacer esto usando Google Closure Compiler type expressions. Pones un signo igual después del tipo así:
function test(/**String=*/arg) {}
40
Author: studgeek,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-04-12 20:27:19
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-04-12 20:27:19