I have a function of a js class which can return a String or undefined. Now I want to insert the return statement into the function's documentation.
/**
* Test documentation.
*
* @param {(String|Number)} value - A String or a number containing a number.
*
* @returns {(String|undefined)} - Returns a String or undefined.
*/
nullOrString(value) {
// ...
}
But when I call the function, the documentation of the return statement only returns String and not (String | undefined).
I also tried it with null instead of undefined, because undefined is returned by default by all functions without a return statement.
So how can I add to my documentation that a undefined or null is returned?
EDIT: Add another test function. Please notice thate these examples are test functions and do not have to make sense.
/**
* Test documentation function.
*
* @param {(String|Number)} input - Input String.
*
* @returns {null|undefined} - Returns null when input is numeric, otherwise returns undefined.
*/
undefinedOrNull(input) {
if (!isNaN(parseFloat(input))) return null;
return undefined;
}
Visual studio code returns:
undefinedOrNull(input: string | number): null
Input String.
Test documentation function.
@returns — - Returns null when input is numeric, otherwise returns undefined.
