[英]Notification when function is registered on e.g. $(document).ready()
[英]How to document destructured function arguments? e.g. `a` when writing `const fn = ({a}) => {/* code */}`
我写了很多代码,例如:
const MyFn = ({myInput}) => {
// code
};
我应该如何记录这些输入的类型?
如果我不使用解构,我会写这样的东西:
/**
* @param {Number} myArg It's a number
*/
const MyFn = (myArg) => {
// code
};
...而我的 IDE(VS Code)会选择它并用它来提出有用的建议。
({myInput})
的解构语法的等效 jsdoc 是什么?
从具有属性的文档:
记录解构参数
/** * Assign the project to an employee. * @param {Object} employee - The employee who is responsible for the project. * @param {string} employee.name - The name of the employee. * @param {string} employee.department - The employee's department. */ Project.prototype.assign = function({ name, department }) { //... };
基本上,您为对象/数组包含一个@param
,然后为您从中解构的内容包含一个@param
。
因此,将其应用于您的代码:
/**
* @param {Object} thingy - The description for the object you're expecting
* @param {TypeForMyInput} thingy.myInput - The description of the destructured property
*/
const MyFn = ({myInput}) => {
// code
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.