5

Google implies that JsDoc is supported:

Custom functions will appear in this list if their script includes a JsDoc @customfunction tag, as in the DOUBLE() example below.

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:

enter image description here

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).

TheMaster
  • 45,448
  • 6
  • 62
  • 85
Magne
  • 16,401
  • 10
  • 68
  • 88

1 Answers1

6

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.

Iamblichus
  • 18,540
  • 2
  • 11
  • 27
  • 1
    Thanks for the suggestion. Not very familiar with submitting issue requests there, but now I did submit this one: https://issuetracker.google.com/issues/156230902 – Magne May 11 '20 at 16:32
  • 1
    @Magne Thank you for reporting this. I updated my answer with the link you referenced, so that people with your same question can find this easily. – Iamblichus May 12 '20 at 12:28