如何在JSDoc中指定对象数组作为参数或返回值? [英] How to specify an array of objects as a parameter or return value in JSDoc?
问题描述
在JSDoc中,如果您具有特定类型的数组(例如字符串数组),则我可以找到的最佳文档显示使用以下内容:
In JSDoc, the best documentation I can find shows to use the following if you have an array of a specific type (such as an array of strings) as:
/**
* @param {Array.<string>} myStrings All my awesome strings
*/
function blah(myStrings){
//stuff here...
}
您将如何替换以下内容问号指定对象数组吗?
How would you replace the below question marks specify an array of objects?
/**
* @param {???????} myObjects All of my equally awesome objects
*/
function blah(myObjects){
//stuff here...
}
推荐答案
您应该更具体地定义JSDoc的含义-这是一个通用术语,几乎涵盖了所有用于JavaScript的JavaDoc风格的文档工具。
You should be more specific what you mean by JSDoc - this is a generic term covering pretty much all the JavaDoc-style documentation tools for JavaScript.
您用于字符串数组的语法类似于 Google Closure Compiler 。
The syntax you used for array of strings looks like the one supported by Google Closure Compiler.
使用此方法,对象数组将为:
Using this, an array of Objects would be:
/**
* @param {Array.<Object>} myObjects
*/
或者只是任何东西的数组-这几乎可以与所有文档工具一起使用:
Or just an array of anything - this should work with pretty much all doc tools:
/**
* @param {Array} myArray
*/
jsdoc-toolkit , JSDoc 3 和 JSDuck 支持以下语法来表示对象数组:
jsdoc-toolkit, JSDoc 3, and JSDuck support the following syntax to denote an array of objects:
/**
* @param {Object[]} myArray
*/
EDIT
如果您知道键的键和变量类型您还可以执行以下值:
EDIT
In case you know the keys and the variable type of the values you can also do:
/**
* @param {Array.<{myNumber: Number, myString: String, myArray: Array}>} myObjects
*/
或
/**
* @param {{myNumber: Number, myString: String, myArray: Array}[]} myObjects
*/
这篇关于如何在JSDoc中指定对象数组作为参数或返回值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!