[英]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 中进行了测试。 工作正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.