使用 TypeDoc 记录接口

Document interfaces using TypeDoc

我正在使用 TypeDoc 来记录我的 TypeScript 代码:

/**
 * @param timestampValue Date in timestamp format
 */
const getDaysInTimestamp = (timestampValue: number): number => {
  return Math.round(timestampValue / 1000)
}

问题是我像这样使用 React 功能组件:

interface Props {
  useLocalStorage?: boolean
  useCookies?: boolean
}

const Application: React.FunctionComponent<Props> = (props) => {
  return (
    <>
      ...
    </>
  )
}

因此您可以像这样使用它:

<Application useLocalStorage useCookies >
  ...
</Application>

但是使用这种结构我无法详细记录 Applicationprops。我能做的最好的是:

/**
 * @param props Props from Application component
 */
const Application: React.FunctionComponent<Props> = (props) => {
  ...

我尝试使用这种类型的表示法,但不受支持:

/**
 * @param props.useLocalStorage Enable the component to store some data in the localStorage
 * @param props.useCookies Enable the component to store and read cookies
 */
const Application: React.FunctionComponent<Props> = (props) => {
  ...

所以我最后的机会是直接记录界面。我的问题是:有没有办法为接口的每个属性编写 TypeDoc?可能与此类似:

/**
 * @param useLocalStorage Enable the component to store some data in the localStorage
 * @param useCookies Enable the component to store and read cookies
 */
interface Props {
  useLocalStorage?: boolean
  useCookies?: boolean
}

您知道如何实施吗?

您可以向接口添加类型注释,类似于 类。

interface Props {
  /** Enable the component to store some data in the localStorage */
  useLocalStorage?: boolean

  /** Enable the component to store and read cookies */
  useCookies?: boolean
}

@typeparam 选项也可用于描述泛型类型,但我不确定它是否支持 Props.useLocalStorage 语法。

/**
 * @typeParam T  Comment for type `T`.
 * You may also use the template tag.
 * @template T comment for type `T`.
 */
function doSomething<T>(target: T, text: string): number;