【问题标题】:How to document generic type parameters?如何记录泛型类型参数?
【发布时间】:2021-12-26 11:19:44
【问题描述】:

假设下面是一个泛型类型,我应该使用什么来代替 ??? 来正确记录 T

/**
 * ??? The description of T.
 */
class MyClass<T> {
}

在 C# 中,我会使用 &lt;typeparam&gt;。是否有官方等效的 JSDoc?

【问题讨论】:

标签: typescript jsdoc


【解决方案1】:

VLAZ 在 cmets 中指出 @template 有效,但在官方 JSDoc 文档中未提及。但是,Typescript 自己的 JSDoc 参考 (link) 中提到了它:

您可以使用@template 标签声明类型参数。这使您可以创建通用的函数、类或类型:

例子:

/**
 * Description of the class MyClass.
 * 
 * @template T Description of the type parameter T.
 */
class MyClass<T> {
    constructor(public readonly x: T) {}
}

当我将鼠标悬停在构造函数中 T 的出现时,文本 “类型参数 T 的描述。” 出现在 Typescript Playground 中,所以这似乎确实有效。

Playground Link

【讨论】:

    猜你喜欢
    • 2013-04-07
    • 1970-01-01
    • 2011-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多