首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用TypeDoc记录界面

使用TypeDoc记录界面
EN

Stack Overflow用户
提问于 2020-04-23 00:20:09
回答 1查看 1.4K关注 0票数 0

我使用TypeDoc来记录我的TypeScript代码,就像这样:

代码语言:javascript
复制
/**
 * @param timestampValue Date in timestamp format
 */
const getDaysInTimestamp = (timestampValue: number): number => {
  return Math.round(timestampValue / 1000)
}

问题是我使用的React函数组件是这样的:

代码语言:javascript
复制
interface Props {
  useLocalStorage?: boolean
  useCookies?: boolean
}

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

所以你可以像这样使用它:

代码语言:javascript
复制
<Application useLocalStorage useCookies >
  ...
</Application>

但是由于这种结构,我不能详细地记录Applicationprops。我能做的最多就是:

代码语言:javascript
复制
/**
 * @param props Props from Application component
 */
const Application: React.FunctionComponent<Props> = (props) => {
  ...

我尝试使用这种类型的符号,但它不受支持:

代码语言:javascript
复制
/**
 * @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?也许是类似的东西:

代码语言:javascript
复制
/**
 * @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
}

你知道如何实现它吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-04-26 01:42:00

您可以向接口添加类型批注,方法与对类进行添加的方式类似。

代码语言:javascript
复制
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语法。

代码语言:javascript
复制
/**
 * @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;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61370015

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档