【问题标题】:In JsDoc 3, what's the proper way to annotate a returned object?在 JsDoc 3 中,注释返回对象的正确方法是什么?
【发布时间】:2023-04-09 21:40:01
【问题描述】:

我在我的 React 项目中使用 JSDoc 3.6.4。我已经定义了以下钩子...

import { useState } from "react";

/**
 * The form hook.  Sets handlers and initial properties of a form. 
 *
 * @param {Object.<string, string>} initialValue
 * @returns {object}
 */
const useForm = (initialValue = {}) => {
  const [values, setValues] = useState(initialValue);

  const reset = () => {
    setValues(initialValue);
  };

  const handleChange = ({ target }) => {
    setValues((values) => ({
      ...values,
      [target.name]: target.value,
    }));
  };

  return {
    handleChange,
    values,
    reset,
    setValues,
  };
};

export default useForm;

当返回多个内容时,记录返回内容的正确方法是什么?我想放的不仅仅是 {object},这就是我现在所拥有的。

【问题讨论】:

    标签: jsdoc


    【解决方案1】:

    您可以使用@typedef 注释。

    正如您在截屏视频中看到的那样:

    • VS Code 可以看出bar 返回Foo
    • 当您将鼠标悬停在@return {Foo} 上时,VS Code 可以显示其形状

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-08
      • 2014-08-04
      • 2017-02-06
      • 2011-12-13
      • 2011-04-26
      • 2020-05-26
      • 2012-11-30
      • 2011-01-22
      相关资源
      最近更新 更多