假设下面是一个通用类型,我应该使用什么来代替
???
来正确记录 T
?
/**
* ??? The description of T.
*/
class MyClass<T> {
}
<typeparam>
。是否有官方的 JSDoc 等效版本?
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 中,因此这似乎确实有效。
对于那些正在寻找 TsDoc 的人,您可以使用 https://tsdoc.org/pages/tags/typeparam/
/*
* @typeParam T - Description of T
*/
class MyClass<T> {
}