microsoft / tsdoc

A doc comment standard for TypeScript
https://tsdoc.org/
MIT License
4.74k stars 131 forks source link

Add an @member tag for documenting interface members outside of the interface #208

Open iansan5653 opened 4 years ago

iansan5653 commented 4 years ago

Sometimes you have a generic base interface type that you extend from, and you want to documenting a member of the extending interface without having to redeclare that member. In this instance, it would be useful to be able to document interface members in the interface's description. This is better explained in an example:

/**
 * A generic building.
 */
interface Building {
  /**
   * The total area of the building in sq. ft.
   */
  area: number;
}

// Annoying and prone to breaking if the base interface changes:

/**
 * A residential house that someone might live in.
 */
interface HouseA extends Building {
  /**
   * The total area of the house in sq. ft. House area doesn't include garages,
   * attics, and basements.
   */
  area: number;
  /**
   * The number of people living in the house.
   */
  residents: number;
}

// A preferable solution:

/**
 * A residential house that someone might live in.
 * @member area - The total area of the house in sq. ft. House area doesn't
 * include garages, attics, and basements.
 */
interface HouseB extends Building {
  /**
   * The number of people living in the house.
   */
  residents: number;
}
octogonz commented 4 years ago

My opinion is that if we're extending the meaning of area, we should probably redeclare it:

/**
 * A residential house that someone might live in.
 */
interface HouseB extends Building {
  /**
   * The number of people living in the house.
   */
  residents: number;

  /**
   * The total area of the house in sq. ft. House area doesn't
   * include garages, attics, and basements.
   */
  area: number;
}

@member seems to go against a couple of software engineering principles:

I'm open to other views, though!