Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to document generic type parameters?

Assuming a generic type below, what should I use in place of ??? to properly document T?

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

In C# I'd use <typeparam>. Is there an official JSDoc equivalent?

like image 848
Branko Dimitrijevic Avatar asked Feb 21 '26 19:02

Branko Dimitrijevic


1 Answers

VLAZ notes in the comments that @template works but isn't mentioned in the official JSDoc documentation. It is, however, mentioned in Typescript's own JSDoc reference:

You can declare type parameters with the @template tag. This lets you make functions, classes, or types that are generic:

Example:

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

The text "Description of the type parameter T." appears in the Typescript Playground when I hover over the occurrence of T in the constructor, so this does seem to work.

Playground Link


If instead of JSDoc you want to use TSDoc, then the tag is @typeParam.

like image 137
kaya3 Avatar answered Feb 24 '26 14:02

kaya3



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!