以前我总是记录我的对象参数如下:
/**
* Description of the function
*
* @param {Object} config - The configuration
* @param {String} config.foo
* @param {Boolean} [config.bar] - Optional value
* @return {String}
*/
function doSomething (config = {}) {
const { foo, bar } = config;
console.log(foo, bar);
// do something
}
Run Code Online (Sandbox Code Playgroud)
但我不确定desctructured函数参数的最佳方法是什么.我是否只是忽略了对象,以某种方式定义它或者记录它的最佳方式是什么?
/**
* Description of the function
*
* @param {String} foo
* @param {Boolean} [bar] - Optional value
* @return {String}
*/
function doSomething ({ foo, bar } = {}) …Run Code Online (Sandbox Code Playgroud) 我正在尝试 JSDoc 一个简单的带有钩子的 React Typescript 组件。不幸的是,我似乎找不到使 JSDoc 与声明的解构数组一起工作的方法。有一些 与解构对象参数相关的答案,但这些对数组不起作用。
/**
* @property {boolean} 0 - documentation for isLoading
* @property {func} 1 - documentation for setIsLoading
*/
const [isLoading, setIsLoading] = React.useState<boolean>(false);
Run Code Online (Sandbox Code Playgroud)
更新 1:仍然无法找到记录此解构的方法。有一个极端情况,如果我自定义键入一个对象,它会起作用:
export type AuthFormInput = {
/** Value of the Email input field */
email: string;
/** Value of the Password input field */
password: string;
};
const [form, setForm] = React.useState<AuthFormInput>({
email: '',
password: ''
});
...
// JSDoc will work here …Run Code Online (Sandbox Code Playgroud)