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中正确注释 descructured和重命名的函数参数?
答案 0 :(得分:3)
在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中测试的。工作正常。