在 TSDoc 中输入 React 道具的正确格式是什么?

What is the proper format for typing React props in TSDoc?

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

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

是否有首选方法?

您想记录道具界面,而不是组件本身。这意味着这与 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.