Simple question, how do I document that \"Mixed-type\"? I know I could just list all possible types like {null|undefined|String|Number|Object}
and end up finding my
In JSDoc, you can describe values in different ways. For example, using the following tags @type
, @param
, @return
.
You can specify optional values using the "?". Here is an example
/**
* Returns string or null
*
* @param {?string} nullableStringArgument
*
* @return {?string}
*/
function returnNullableString (nullableStringArgument = null) {
/** @type {?string} */
const nullableString = [null, 'string'][Math.floor(Math.random() * 2)];
return nullableString;
}