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

问题描述

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

MyProps

有首选的方法吗?

解决方法

您想记录 props 接口,而不是组件本身。这意味着这与 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= 上时,您应该会看到文档。

enter image description here

Playground example.