Skip to content

Latest commit

 

History

History
62 lines (48 loc) · 2.46 KB

File metadata and controls

62 lines (48 loc) · 2.46 KB

Item 68: Use TSDoc for API Comments

Things to Remember

  • Use JSDoc-/TSDoc-formatted comments to document exported functions, classes, and types. This helps editors surface information for your users when it's most relevant.
  • Use @param, @returns, and Markdown for formatting.
  • Avoid including type information in documentation (see pass:[Item 31]).
  • Mark deprecated APIs with @deprecated.

Code Samples

// Generate a greeting. Result is formatted for display.
function greet(name: string, title: string) {
  return `Hello ${title} ${name}`;
}

💻 playground


/** Generate a greeting. Result is formatted for display. */
function greetJSDoc(name: string, title: string) {
  return `Hello ${title} ${name}`;
}

💻 playground


/**
 * Generate a greeting.
 * @param name Name of the person to greet
 * @param title The person's title
 * @returns A greeting formatted for human consumption.
 */
function greetFullTSDoc(name: string, title: string) {
  return `Hello ${title} ${name}`;
}

💻 playground


/** A measurement performed at a time and place. */
interface Measurement {
  /** Where was the measurement made? */
  position: Vector3D;
  /** When was the measurement made? In seconds since epoch. */
  time: number;
  /** Observed momentum */
  momentum: Vector3D;
}

💻 playground