jsdoces6-class

How to use JSDoc to document an ES6 class property


I'm using the documentation package, but cannot figure out how to get it to document class properties (that aren't defined via getters and setters).

As the following just generates class documentation for SomeClass, but omits the someProperty documentation.

/**
 * SomeClass is an example class for my question.
 * @class
 * @constructor
 * @public
 */
class SomeClass {
    constructor () {
        this.someProperty = true  // how do I document this?
    }

    /**
     * someProperty is an example property that is set to `true`
     * @property {boolean} someProperty
     * @public
     */
}

An aside: the @constructor on the class jsdoc is a documentation thing.


Solution

  • Move the JSDoc for someProperty into the constructor where it is first defined:

    /**
     * SomeClass is an example class for my question.
     * @class
     * @constructor
     * @public
     */
    class SomeClass {
        constructor () {
            /**
             * someProperty is an example property that is set to `true`
             * @type {boolean}
             * @public
             */
            this.someProperty = true
        }
    }
    

    I'm unsure if there is a way of accomplishing it with the documentation package using an approach that doesn't involve inlining the JSDocs into the constructor.