使用 JSDoc 我将如何注释一个解构的重命名函数参数?
Using JSDoc how would I annotate a destructured renamed function argument?
ES6 语法允许重命名解构变量和参数。
变量:
const {requestID: _requestID, notifyChanges: _notifyChanges} = someObject;
console.log(_requestID, _notifyChanges);
参数:
/**
* Creates a cloud ready request.
* @param {String} requestID Request ID used for for tracing and logs
* @param {Boolean} [notifyChanges] Send an event to the message queue.
*/
function createRequest({
requestID: _requestID,
notifyChanges: _notifyChanges = false,
}) {
console.log(_requestID, _notifyChanges);
});
即使上面的 JavaScript 代码有效,JSDoc 也会显示错误:
Parameter 'requestID' described in JSDoc does not appear in function signature
如何在 JSDoc 中正确注释 结构化和重命名的 函数参数?
在 JSDoc 参数名称中使用冒号:
/**
* Creates a cloud ready request.
* @param {String} _requestID:requestID Request ID used for for tracing and logs
* @param {Boolean} [_notifyChanges:notifyChanges] Send an event to the message queue.
*/
function createRequest({
requestID: _requestID,
notifyChanges: _notifyChanges = false,
}) {
console.log(_requestID, _notifyChanges);
});
这是在 WebStorm IDE 2016.2 中测试的。工作正常。
ES6 语法允许重命名解构变量和参数。
变量:
const {requestID: _requestID, notifyChanges: _notifyChanges} = someObject;
console.log(_requestID, _notifyChanges);
参数:
/**
* Creates a cloud ready request.
* @param {String} requestID Request ID used for for tracing and logs
* @param {Boolean} [notifyChanges] Send an event to the message queue.
*/
function createRequest({
requestID: _requestID,
notifyChanges: _notifyChanges = false,
}) {
console.log(_requestID, _notifyChanges);
});
即使上面的 JavaScript 代码有效,JSDoc 也会显示错误:
Parameter 'requestID' described in JSDoc does not appear in function signature
如何在 JSDoc 中正确注释 结构化和重命名的 函数参数?
在 JSDoc 参数名称中使用冒号:
/**
* Creates a cloud ready request.
* @param {String} _requestID:requestID Request ID used for for tracing and logs
* @param {Boolean} [_notifyChanges:notifyChanges] Send an event to the message queue.
*/
function createRequest({
requestID: _requestID,
notifyChanges: _notifyChanges = false,
}) {
console.log(_requestID, _notifyChanges);
});
这是在 WebStorm IDE 2016.2 中测试的。工作正常。