Given the following example:
/**
* An outer function
* @param {number} age - The age to pass to outerFunction
* @returns {#What goes here?#}
*/
function outerFunction(age){
return addTen(age)
}
/**
* Adds 10 to the age
* @param {number} age - The age to add 10 to
* @returns {number} - The age + 10
*/
function addTen(age){
return 10 + age
}
the outerFunction
returns another function's result.
I thought of several ways to document this:
@returns {number}
- We know thataddTen
returns a number, but what if this changes? We will have to update both (or each time it is returned, which could be a lot), which isn't maintainable.@returns {function}
- I am not sure if this is available in JsDoc. I couldn't find it anywhere. This also doesn't feel like it gives much information.@returns {any}
or -@returns {*}
- This isn't particularly helpful to anyone reading the doc.
None of these feel correct to me for the reasons stated.
I guess I want something like
@returns {addTen.return}
So that I am essentially saying "outerFunction
returns whatever type addTen
does".
Note: these are in the same place in this example, but could be contained in multiple files, so using this approach doesn't work, unless it's possible to do this across multiple files.
How do we write JsDoc comments to document that the function returns another function?
Does something similar to my suggestion exist?