9

I'd like to document (in the Google Sheet autocomplete) a custom function with optional arguments, similar to the WEEKDAY function (autocomplete below).

The JSDoc spec on optional arguments does not work. Google does not seem to document this anywhere. How can I create a function with the same visual treatment (both in the argument description and the Example) that Google has?

Google's autocomplete for WEEKDAY

/**
 * Summary of function
 * @param {"example"} arg Argument description
 * @param {"optional"} opt_arg This argument is optional
 * @return {String} Return value description
 * @customfunction
 */
function JSDOC(arg, opt_arg) {
  return
}

Generates this autocomplete:

My custom function autocomplete

This is not a duplicate. I'm specifically asking about optional arguments, as you can see, I've successfully gotten the autocomplete's other features working.

ehfeng
  • 3,807
  • 4
  • 33
  • 42
  • I don't think JSDoc works the way you think it does. It's not an add on to javascript, its an interpreter of your javascript code and generates a document. – TheWizEd Jan 27 '19 at 00:07
  • 1
    @TheWizEd You misunderstand my question. I'm aware that JSDoc is not a "addon" to javascript. I named the function JSDOC just randomly. I'm looking to understand the syntax that Google Apps Script supports for documenting functions, in particular their optional arguments. – ehfeng Jan 27 '19 at 02:01
  • To be clear, both `=` and `[]` didn't work? – TheMaster Jan 27 '19 at 02:06
  • 1
    @ehfeng Is this what you're looking for [Custom Functions in Google Sheets - AutoComplete](https://developers.google.com/apps-script/guides/sheets/functions#autocomplete). Mogsdad has an excellent discussion on this in [How to add “custom function help” to a google spreadsheet](https://stackoverflow.com/a/31326326/1330560), plus a link to a much detailed blog post. – Tedinoz Jan 27 '19 at 10:58
  • @Tedinoz He's specifically looking for arguments to be regarded "optional". – TheMaster Jan 27 '19 at 13:41
  • @TheMaster You're quite right-I deleted the suggestion of a possible duplicate. – Tedinoz Jan 28 '19 at 00:54
  • Yes, both `=` and `[]` don't work. I've read through that article as well, and as @TheMaster mentioned, they don't mention optional arguments. – ehfeng Jan 28 '19 at 03:25

2 Answers2

4

Google Apps Script doesn't support optional params in their JSDoc at this moment.

1

JsDoc isn't fully supported. Specifically optional parameters isn't supported. A related tracker link is here:

https://issuetracker.google.com/issues/156230902

Anyone interested in this issue may add a +1(on the top bar, not as a comment) to this issue. They may also add a new specific feature request for the same.

TheMaster
  • 45,448
  • 6
  • 62
  • 85