如何记录泛型类型参数?

问题描述 投票:0回答:3

假设下面是一个通用类型,我应该使用什么来代替

???
来正确记录
T

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

在 C# 中我会使用

<typeparam>
。是否有官方的 JSDoc 等效版本?

typescript jsdoc
3个回答
14
投票

VLAZ 在评论中指出

@template
可以工作,但官方 JSDoc 文档中没有提及。然而,在 Typescript 自己的 JSDoc 参考中提到了它:

您可以使用

@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 中,因此这似乎确实有效。

游乐场链接


3
投票

对于那些正在寻找 TsDoc 的人,您可以使用 https://tsdoc.org/pages/tags/typeparam/


0
投票
/*
 * @typeParam T - Description of T
 */
class MyClass<T> {

}
© www.soinside.com 2019 - 2024. All rights reserved.