Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to document tuple using JSDoc?

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
}
like image 570
Per Ghosh Avatar asked Mar 13 '26 11:03

Per Ghosh


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
}
like image 191
Marlorn Avatar answered Mar 16 '26 03:03

Marlorn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!