How to document tuple using JSDoc?

Viewed 1316

Is there some sort of standard to document tuples using JSDoc?

Given the following code, is this the correct way to document values at specific index positions in array?

/**
 * @param {Array.<number,number>} tuple_variable description
 * @param {number} tuple_variable[0] description
 * @param {number} tuple_variable[1] description
 */
function document_tuple( tuple_variable: [number,number] ) {
   // omitted
}
1 Answers

If you want a fully-expanded version that includes descriptions of each array element, something like this will work:

/**
 * @typedef {number} MyTupleIndex0 - Description of index 0...
 * @typedef {number} MyTupleIndex1 - Description of index 1...
 * @typedef {[MyTupleIndex0, MyTupleIndex1]} MyTuple
 * @param {MyTuple} tuple_variable
 */
function document_tuple(tuple_variable) {
  // ommited
}

Or, more tersely, but without the descriptions:

/**
 * @param {[number, number]} tuple_variable
 */
function document_tuple(tuple_variable) {
  // ommited
}
Related