better-docs icon indicating copy to clipboard operation
better-docs copied to clipboard

Typescript class decorators and a static factory method creates a class with _1 suffix

Open captnCC opened this issue 5 years ago • 3 comments

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.

captnCC avatar Sep 21 '20 10:09 captnCC

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)?

wojtek-krysiak avatar Sep 21 '20 21:09 wojtek-krysiak

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.

captnCC avatar Sep 22 '20 15:09 captnCC

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.

wojtek-krysiak avatar Sep 22 '20 17:09 wojtek-krysiak