【发布时间】:2020-01-18 10:22:26
【问题描述】:
我正在尝试 JSDoc 一个带有钩子的简单 React Typescript 组件。不幸的是,我似乎找不到使 JSDoc 与声明的解构数组一起工作的方法。有 some answers 与解构对象参数相关,但这些不适用于数组。
/**
* @property {boolean} 0 - documentation for isLoading
* @property {func} 1 - documentation for setIsLoading
*/
const [isLoading, setIsLoading] = React.useState<boolean>(false);
更新 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
const email = form.email;
【问题讨论】:
-
您是否发布了所有相关代码?我没有看到对 JSDoc 或解构数组的任何引用。
-
@RutherfordWonkington JSDoc 确实是单行代码上方的注释块。解构后的数组在
const [isLoading, setIsLoading]。 -
所以你想要 JSDoc 局部变量,对吗?如果有,需要什么?
-
@skyboyer 主要用于记录组件状态,以便以后使用时可以提出对它的引用。
标签: reactjs typescript jsdoc3