如何记录解构的函数参数?例如`a` 写 `const fn = ({a}) => {/* code */}`

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 是什么?

来自Documents with Properties

Documenting a destructuring parameter

/**
 * 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 }) {
    // ...
};

基本上,您为 object/array 添加一个 @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
};

您也可以使用 @typedef 来执行此操作。