better-docs
better-docs copied to clipboard
Typescript class decorators and a static factory method creates a class with _1 suffix
When writing a class that has a static factory method which creates a new instance of the class itself, the class will be suffixed with _1 in the created docs. Sample:
/**
* MyClass
*/
@myDecorator()
class MyClass {
static factory(){
return new MyClass()
}
constructor(){}
}
The JsDoc than contains a Class MyClass_1 that misses the class description.
this is a bug. Before passing the code to jsdoc we transpile it with ts. and it changes decorators.
not sure. but can you first create class with jsdoc and then add decorator before exporting the file? (not sure this in possible in ts)?
The decorator has to be before the class itself. The order between the JSDoc Comment and the decorator should be irrelevant.
I played bit around and removed the decorator with a regex before passing the source to the ts compiler. That worked but I don't know if it is a feasible option to create a regex that catches all decorators but ignores the JSDoc annotations.
tbh, the current way how better docs works is not scallable. In the long run we will have to get rid of jsdoc and parse everything on our own. But this is a huge project (week of work) and not sure we can invest on this right now.