【问题标题】:What is the proper format for typing React props in TSDoc?在 TSDoc 中输入 React 道具的正确格式是什么?
【发布时间】:2021-02-20 01:28:56
【问题描述】:

我正在尝试将 cmets 的 TSDoc 标准应用于用 Typescript 编写的 React 项目(着眼于使用 Typedoc 生成文档),但对于注释 React @987654321 的首选方式找不到任何明确的答案@ 目的。到目前为止,我已经有了这个,MyProps 是一个接口:

/**
 * Description of my function component
 * @param props - React props
 */
export default function MyComponent(props: MyProps) { ...

有首选方法吗?

【问题讨论】:

    标签: reactjs typescript typedoc tsdoc


    【解决方案1】:

    您想要记录道具界面,而不是组件本身。这意味着这与documenting fields of an interface. 相同

    import React from 'react'
    
    interface FooProps {
      /** Testing 123 */
      foo: string
    }
    
    function Foo({foo}: FooProps) {
      return <>{foo}</>
    }
    
    <Foo foo="bar" />
    

    当您将鼠标悬停在最后一行的 foo= 上时,您应该会看到文档。

    Playground example.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-22
      • 2021-10-22
      • 2015-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多