JSDoc for Class Constructors

Generate JSDoc or TSDoc for class constructors with parameter documentation, @class tags, and property initialization descriptions.

Classes

Detailed Explanation

Documenting Class Constructors

Class constructors initialize object instances. The documentation should cover what the class represents, what the constructor parameters are, and any side effects of construction.

Example Signature

class DatabaseConnection {
  constructor(
    host: string,
    port: number = 5432,
    options?: { ssl: boolean; timeout: number }
  )
}

Generated JSDoc

/**
 * Manages a connection to a PostgreSQL database.
 *
 * @class DatabaseConnection
 */

/**
 * Creates a new DatabaseConnection instance.
 *
 * @param {string} host - The database server hostname or IP address.
 * @param {number} [port=5432] - The port number. Defaults to 5432.
 * @param {object} [options] - Additional connection options.
 * @param {boolean} options.ssl - Whether to use SSL encryption.
 * @param {number} options.timeout - Connection timeout in milliseconds.
 *
 * @throws {ConnectionError} If the host is unreachable.
 *
 * @example
 * ```typescript
 * const db = new DatabaseConnection("localhost", 5432, {
 *   ssl: true,
 *   timeout: 5000,
 * });
 * ```
 */

Two-Level Documentation

Classes typically need two comment blocks:

  1. Class-level: Describes the class purpose, using @class tag
  2. Constructor-level: Documents the constructor parameters

Documenting Object Parameters

When a parameter is an object with known properties, document each property with dot notation:

@param {object} options - Connection options.
@param {boolean} options.ssl - Use SSL encryption.
@param {number} options.timeout - Timeout in ms.

Private/Protected Members

In TSDoc, use @internal for members that should not appear in public API docs, and @privateRemarks for notes visible only to contributors.

Use Case

Documenting service classes, database drivers, HTTP client wrappers, state management stores, and any class where construction involves configuration that other developers need to understand.

Try It — JSDoc / TSDoc Generator

Open full tool