I just cannot figure out how to correctly document callback using @param
so that Visual Studio 2017 intellisense will understand it.
For example:
/**
* @param {string} file absolute path
* @param {Function} callback called when done
*/
function loadFile(path, callback) {
/// code
}
The callback accepts Error
and string
as arguments (Node.js style), how to document it?
I just cannot figure out how to correctly document callback using @param
so that Visual Studio 2017 intellisense will understand it.
For example:
/**
* @param {string} file absolute path
* @param {Function} callback called when done
*/
function loadFile(path, callback) {
/// code
}
The callback accepts Error
and string
as arguments (Node.js style), how to document it?
2 Answers
Reset to default 13This pattern works:
/**
* @param {string} file absolute path
* @param {function(Error, string):void} callback called when done
*/
function loadFile(path, callback) {
/// code
}
void
here stands for no return value, can be replaced with callback return value (eg.: {function(value):boolean}
for a predicate).
How to document parameter names I do not know.
To annotate the callback parameters with types and names, do this:
/**
* @param {string} path - absolute file path
* @param {(error: string, namedParameter: type)} callback - callback called when done
*/
function loadFile(path, callback) {
/// code
}