How to document generic type parameters?

Viewed 547

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?

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 (link):

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

Related