最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to document callback parameters in JSDoc for Visual Studio intellisense? - Stack Overflow

programmeradmin4浏览0评论

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?

Share Improve this question asked Nov 23, 2017 at 15:41 Tomáš ZatoTomáš Zato 53.2k63 gold badges308 silver badges822 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 13

This 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
}
发布评论

评论列表(0)

  1. 暂无评论