Document overloaded functions and constructors

2

I have the following class constructor:

class Logger {
  /** @constructs
      @param { number } minlevel Minimal level to shown log
      @param { function } callback to really do the process
  */
  constructor( minlevel, callback ) {
    if( minlevel instanceof Logger ) {
      // Duplicar el objeto.
      this.$callback = minlevel.$callback;

      if( typeof( callback ) === 'number' ) {
        this.$minLevel = callback;
      } else {
        this.$minLevel = minlevel.$minLevel;
      }
    } else {
      // Nueva instancia.
      if( typeof( callback ) != 'function' ) throw TypeError( );

      this.$minLevel = minlevel;
      this.$callback = callback;
    }
  }
}

This constructor has 2 overloads (use cases, with different types of arguments and different results). Expressed in TypeScript (to clarify), it would be like this:

  • constructor( other : Logger, minlevel? : number )

    Used to clone an instance; generates a copy, with an optional minlevel argument.

  • constructor( minlevel : number, callback : Function )

    Used to create a new instance without relying on any other.

I would like to document both overloads using JSDoc , but I can not find the correct way. As it is now, it generates

which is what I expect for the second overload .

How can I document functions / constructors / getters / setters overloaded using JSDoc?

    
asked by Trauma 13.10.2018 в 14:39
source

1 answer

2

Finally, I found the solution (in English): How Do I Document an Overloaded Constructor

In that link, literally

is indicated
  

You need to nestle the start and end of each comment

However, I think it is more appropriate to indicate that the descriptions of the different overloads have to be immediately placed next to each other :

class Logger {
  /**
    @constructs
    @param { number } minlevel Minimal level to shown logs
    @param { function } callback to really do the process
  *//**
    @constructs
    @param { Logger } instance Instance to copy
    @param { number } minlevel Minimal level to shown logs
  */
  constructor( minlevel, callback ) {
    if( minlevel instanceof Logger ) {
      // Duplicar el objeto.
      this.$callback = minlevel.$callback;

      if( typeof( callback ) === 'number' ) {
        this.$minLevel = callback;
      } else {
        this.$minLevel = minlevel.$minLevel;
      }
    } else {
      // Nueva instancia.
      if( typeof( callback ) != 'function' ) throw TypeError( );

      this.$minLevel = minlevel;
      this.$callback = callback;
    }
  }
}

The result obtained, now yes, is satisfactory:

    
answered by 13.10.2018 / 20:53
source