简体   繁体   English

使用 TypeDoc 的文档接口

[英]Document interfaces using TypeDoc

I'm using TypeDoc to document my TypeScript code just like that:我正在使用TypeDoc来记录我的 TypeScript 代码,就像这样:

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

Problem is that I use React functional components like that:问题是我使用这样的 React 功能组件:

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

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

So you can use it like:所以你可以像这样使用它:

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

But with this structure I'm not able to document the props of Application in details.但是使用这种结构,我无法详细记录Applicationprops Best I can do is this:我能做的最好的就是:

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

I tried using this type of notation but it's not supported:我尝试使用这种类型的表示法,但它不受支持:

/**
 * @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) => {
  ...

So my last chance is to document the interface directly.所以我最后的机会是直接记录接口。 My question is: Is there a way to write TypeDoc for each attributes of an interface?我的问题是:有没有办法为接口的每个属性编写 TypeDoc? Maybe something similar to that:也许类似的东西:

/**
 * @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
}

Have you any idea how it can be implemented?您知道如何实施吗?

You can add type annotations to interfaces similar to how you would for classes.您可以向接口添加类型注释,类似于为类添加类型注释。

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

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

The @typeparam option is also available for describing generic types however I'm not sure it supports the Props.useLocalStorage syntax.@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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM