1

In a TypeScript file, how can I write JSDoc documentation for the generic type parameter of a function?

In the following dummy example, I tried to use @param T to provide documentation on the generic type parameter T:

/**
 * A function that processes an array.
 * @param arr The array to be processed.
 * @param T The type of each element in the array.
 */
function processArray<T>(arr: T[]) {
  console.log(arr);
  /* ... */
}

(Link to TypeScript playground)

When I hover over the function parameter arr, the documentation tooltip can show the description that I provided via @param arr.

documentation for arr

However, when I hover over the generic type parameter T, it does not show the documentation that I provided via @param T:

documentation tooltip of generic type parameter

Which JSDoc tag should I use such that the documentation can show inside the tooltip of the generic type parameter? If that is not supported, is it a good practice to use the @param tag (e.g. @param T)?

AnsonH
  • 2,460
  • 2
  • 15
  • 29
  • 1
    Found in [this other answer](https://stackoverflow.com/questions/65689718/how-to-pass-a-generic-type-argument-with-jsdoc), it suggests to use `@template T`. – zmo Feb 16 '23 at 19:38

0 Answers0