How do you document JSDoc with mixed parameter type?

和自甴很熟 提交于 2019-11-30 10:55:41

You can use the | separator to specify multiple types in the method type signature:

/**
 * Some method
 * @param {Object|string|number} param The parameter.
 * @returns {Object|string|number} The modified param.
 */
function doSomething(param) {
    return etc..
};

Google Closure Compiler Docs recommend the following form - which looks official as it is the same as found on usejsdoc.org:

/**
 * Some method
 * @param {(Object|string|number)} param The parameter.
 * @returns {(Object|undefined)} The modified param.
 */
function doSomething(param) {
    return etc..
};

To cite the above linked closure compiler docs:

Note the parentheses, which are required.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!