【问题标题】:How to document tuple using JSDoc?如何使用 JSDoc 记录元组?
【发布时间】:2021-02-20 15:28:34
【问题描述】:

是否有某种标准来使用 JSDoc 记录元组?

鉴于以下代码,这是在数组中特定索引位置记录值的正确方法吗?

/**
 * @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
}

【问题讨论】:

标签: typescript jsdoc


【解决方案1】:

如果您想要一个包含每个数组元素描述的完全扩展版本,则可以使用以下方法:

/**
 * @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
}

或者,更简洁,但没有描述:

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

【讨论】:

    猜你喜欢
    • 2019-04-06
    • 2012-11-04
    • 2013-05-30
    • 1970-01-01
    • 1970-01-01
    • 2012-04-27
    • 2023-03-23
    • 2017-11-20
    • 2011-12-11
    相关资源
    最近更新 更多