简体   繁体   English

如何在JSDoc中指定对象数组作为参数或返回值?

[英]How to specify an array of objects as a parameter or return value in 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: 在JSDoc中,如果您有一个特定类型的数组(例如字符串数组),我可以找到的最佳文档显示使用以下内容:

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

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. 您应该更具体地了解JSDoc的含义 - 这是一个涵盖JavaScript的几乎所有JavaDoc样式文档工具的通用术语。

The syntax you used for array of strings looks like the one supported by Google Closure Compiler . 您用于字符串数组的语法类似于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: 或者只是一系列的东西 - 这应该适用于几乎所有的doc工具:

/**
 * @param {Array} myArray
 */

jsdoc-toolkit , JSDoc 3 , and JSDuck support the following syntax to denote an array of objects: jsdoc-toolkitJSDoc 3JSDuck支持以下语法来表示对象数组:

/**
 * @param {Object[]} myArray
 */

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

or 要么

/**
 * @param {{myNumber: Number, myString: String, myArray: Array}[]} myObjects
 */

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM