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.
As with Java, to document a function, variable or class. You just have to create a comment before the element you want to document. The only thing you have to keep in mind is that the comment needs to start with /** and end with */ , like so: /** * This is a JSDoc comment * ...
You can use most JSDoc type syntax and any TypeScript syntax, from the most basic like string to the most advanced, like conditional types.
JSDoc is a markup language used to annotate JavaScript source code files. Using comments containing JSDoc, programmers can add documentation describing the application programming interface of the code they're creating.
JSDoc comments are used for documentation lookup with Ctrl+Q in JavaScript and TypeScript, see JavaScript documentation look-up and TypeScript documentation look-up, as well as for type annotations and method return type hints in chained methods.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With