问题描述
Google 暗示支持 JsDoc:
如果自定义函数的脚本包含JsDoc @customfunction 标记,如下面的 DOUBLE() 示例所示.
图片提供:https://yagisanatode.com/2018/08/24/google-apps-script-how-to-make-a-custom-function-to-use-in-谷歌表格/
使用 JsDoc,您应该能够根据此来源执行以下操作:https://jsdoc.app/tags-param.html#可选参数和默认值
/*** @param {number} [value2] - 要添加到 value1 的其他数字或范围.*/
并且,使用默认值:
/*** @param {number} [value2=100] - 要添加到 value1 的其他数字或范围.*/
但我在 Google 表格中对此进行了测试,但均无效.甚至不是建议的 Google Closure Compiler 语法(以防万一):
/*** @param {number=} value2 - 要添加到 value1 的其他数字或范围.*/
目前我采用了不太优雅的方法:
/*** @param {number} value2 - [可选] 要添加到 value1 的其他数字或范围.*/
那么,我在哪里可以找到有关 Google 表格支持 JsDoc 的哪一部分的文档?
如果您能展示一种使用 JsDoc 记录可选参数的方法,该方法可从屏幕截图中获得所需的结果(这比我当前的不雅解决方案更好),则加分.
Sheets 自定义函数似乎不支持 JsDoc 可选参数功能,但找不到相关的官方文档.
我建议您在此组件中提交功能请求以要求此功能,或者至少更详细地记录支持哪些功能.
更新:
OP 在问题跟踪器中提交了关于此的功能请求:
任何想要跟踪此信息的人都可以点击参考页面左上角的星星.
Google implies that JsDoc is supported:
https://developers.google.com/apps-script/guides/sheets/functions
But it doesn't seem that JsDoc is supported in full, and I can't find the documentation that shows what is supported and not.
I'm particularly looking for a way to document that a parameter for a custom function is optional. Like this, for value2:
Image courtesy of: https://yagisanatode.com/2018/08/24/google-apps-script-how-to-make-a-custom-function-to-use-in-google-sheets/
Using JsDoc, you should be able to do the following, based on this source:https://jsdoc.app/tags-param.html#optional-parameters-and-default-values
/**
* @param {number} [value2] - Additional numbers or ranges to add to value1.
*/
And, with a default value:
/**
* @param {number} [value2=100] - Additional numbers or ranges to add to value1.
*/
But I tested this in Google sheets, and none of this works. Not even the suggested Google Closure Compiler syntax (in case that should work):
/**
* @param {number=} value2 - Additional numbers or ranges to add to value1.
*/
Currently I have resorted to the less elegant:
/**
* @param {number} value2 - [OPTIONAL] Additional numbers or ranges to add to value1.
*/
So, where can I find the documentation over what part of JsDoc is supported in Google Sheets?
Bonus points if you can show a way to document the optional parameter using JsDoc that achieves the desired result from the screenshot (which is better than my current inelegant solution).
JsDoc optional arguments feature doesn't seem to be supported for Sheets custom functions, but no official documentation can be found for this.
I'd suggest you to file a Feature Request in this component to ask for this functionality, or at least to document in more detail what functionality is supported.
Update:
A Feature Request regarding this was submitted in Issue Tracker by OP:
Anyone who want to keep track of this can click the star on the top left on the referenced page.
这篇关于Google Sheets 自定义函数支持多少 JsDoc?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!