@memberof for shared class methods?

267 views Asked by At

In my library I am extending types Database and Transaction with the same method query defined in just one place.

If I try to use @memberof Database and @memberof Transaction, the latter overrides the former.

What is the correct way in jsdoc to indicate for a function that it represents a method in two different classes?

1

There are 1 answers

10
aebabis On

I would do it like this:

/**
 * @interface Interface
 * ...
 */

 /**
  * @function query
  * @memberof Interface
  * ...
  */

/**
 * @class Database
 * @implements Interface
 * ...
 */

/**
 * @class Transaction
 * @implements Interface
 * ...
 */

It doesn't necessary matter that Interface isn't defined anywhere in the code as long as no one else wants to implement Interface. If you think they might, then make and extend a base class instead (using prototype inheritance or ES6 classes), and document accordingly.