I'm looking for documentation generator for my JS library. I find JSDuck the most comprehensive and powerful one. But I don't see a way to define type variables for generic classes and functions using its syntax. Quick look at popular JS documentation generators makes me feel that neither of them has a capability of doing that. Here is a pseudo-example of what I'm looking for:
/**
* @class MyArray
* My perfect array class.
* @typevar T
*/
MyArray = function() ...
/**
* @class BirdArray
* Please count birds using this awesome array class.
* @typevar T extends {Bird}
* @extends {MyArray<T>}
*/
BirdArray = function() ...
extend(BirdArray, MyArray);
Sample output:
MyArray<T>
My perfect array class.
BirdArray<T extends Bird> extends MyArray<T>
Please count birds using this awesome array class.
Is there a way of achieving that in JSDuck? If not, is there some JS documentation generator which can do that for me? Please assume that it should be as versatile as JSDuck, to make sure that I'll be able to use arbitrary class inheritance pattern.
Interestingly, Google Closure Compiler has support for generic types, with a syntax like this:
As JSDuck already supports Closure Compiler style type annotations, it should be already possible to write types like
{MyClass.<T>}. JSDuck doesn't however uses a @template tag for a different purpose altogether, but one implement its own custom tag like@typevaror override the builtin@templateto do your bidding using the custom tags system.But as there is no actual generic types support in JSDuck, it won't check your generic types. On the contrary, it will probably complain, that you're referencing an unknown type
Tand others. But it's easy to make JSDuck ignore certain types (or type variables) by using--external=T.One final note. The Closure Compiler doesn't support your
extendssyntax in type variables, and I don't really see why would you writeT extends Birdand then{MyArray<T>}, instead of just writing{MyArray<Bird>}.