我使用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>但是由于这种结构,我不能详细地记录Application的props。我能做的最多就是:
/**
* @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
}你知道如何实现它吗?
发布于 2020-04-26 01:42:00
您可以向接口添加类型批注,方法与对类进行添加的方式类似。
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;https://stackoverflow.com/questions/61370015
复制相似问题