1

How can I document possible configuration properties in function argument in JSDOC:

/**
 * N level expectimax AI.
 *
 * @param {object} cfg  config
 *   cfg.minimaxDepth  - limit for minimax search
 *   cfg.expectiDepth  - limit for expectimax search
 *   cfg.weightFn  - position weight function
 *
 * @constructor
 */
function expectimaxAI(brdEngine, cfg) { ... }

Which markup is to use for cfg.minimaxDepth (cfg.*) parameters?

Is it possible to document synthetic aiCfg type and put reference to it as:

 * @param {aiCfg} cfg  config

or somehow else?

gavenkoa
  • 45,285
  • 19
  • 251
  • 303

1 Answers1

1

After reading official JSDoc 2.x docs I make some hack:

/**
 * @name BlindWeightRandomCfg
 * @function
 * @param {number} left   weight
 * @param {number} right  weight
 * @param {number} up     weight
 * @param {number} down   weight
 */

and refer to non-existing function as:

/**
 * Blind weight random AI.
 *
 * @param {Board} brdEngine  board engine from board.js
 * @param {BlindWeightRandomCfg} cfg  configuration settings
 * @constructor
 */
 ai.BlindWeightRandom = function(brdEngine, cfg) { ... }

Now argument cfg - clickable to definition of BlindWeightRandomCfg!

UPDATE Another possibility for JSDoc 2.x:

/**
 * @name BlindWeightRandomCfg
 * @namespace
 * @property {number} left   weight
 * @property {number} right  weight
 * @property {number} up     weight
 * @property {number} down   weight
 */

and for JSDoc 3.x:

/**
  @typedef PropertiesHash
  @type {object}
  @property {string} id - an ID.
  @property {string} name - your name.
  @property {number} age - your age.
 */

/** @type {PropertiesHash} */
var props;

Seems that @typedef is a solution. Please see other variants and at official docs.

gavenkoa
  • 45,285
  • 19
  • 251
  • 303