クイックリファレンス

JSDoc 3 ドキュメント記法チートシート

JSDoc 3 アノテーションの総合リファレンス:@param、@returns、@typedef、@type、ジェネリクス @template、@async、TypeScript 型チェック対応を網羅。

· 公開日

JSDoc は JavaScript 向けの API ドキュメント生成ツールであり、TypeScript 言語サーバーでも解釈される型アノテーション形式です。

関数アノテーション

/**
 * Calculates total invoice sum including tax.
 *
 * @param {number} subtotal - Net amount before tax.
 * @param {number} [taxRate=0.1] - Optional tax percentage (defaults to 10%).
 * @param {string} [currency='USD'] - Three-letter ISO currency code.
 * @returns {number} The calculated total invoice price.
 * @throws {RangeError} When subtotal is negative.
 */
function calculateTotal(subtotal, taxRate = 0.1, currency = 'USD') {
  if (subtotal < 0) throw new RangeError('Subtotal must be positive');
  return subtotal * (1 + taxRate);
}

型定義とエイリアス(@typedef)

/**
 * @typedef {Object} UserProfile
 * @property {number} id - Unique numeric identifier.
 * @property {string} username - User account handle.
 * @property {string} [email] - Optional contact email address.
 * @property {'admin' | 'editor' | 'member'} role - Access control role.
 */

/**
 * Loads user record from database.
 * @param {number} id
 * @returns {Promise<UserProfile>}
 */
async function getUser(id) {
  // ...
}

よく使われる JSDoc タグ

タグ 説明 例
@type {Type} 変数の型を宣言する /** @type {string[]} */
@param {Type} name 関数の引数を記述する /** @param {HTMLElement} el */
@returns {Type} 戻り値を記述する /** @returns {Promise<void>} */
@async 関数が非同期であることを示す /** @async */
@deprecated シンボルを非推奨としてマークする /** @deprecated Use fetchUser() instead */
@see 外部ドキュメントへのリンク /** @see {@link https://example.com} */
@template T ジェネリック型パラメータを宣言する /** @template T @param {T} item */

リファレンス

関連テーマ