3

I have a simple function that needs to be documented using JSDocs that has an optional nameless object parameter with default values. This is what I am talking about:

function (param1, { attr1 = 0, attr2 = 'something', attr3 = {} } = {}) {
  // do stuff
}

Here is what my current JSDoc look like, but it doesn't seem to be right.

/**
 * @param {string} param1
 * @param {Object} options
 * @param {number} [options.attr1=0]
 * @param {string} [options.attr2='']
 * @param {Object} [options.attr3={}]
 */

How do I appropriately use JSDocs for this particular case?

theJuls
  • 6,788
  • 14
  • 73
  • 160
  • 1
    Possible duplicate of [How to indicate param is optional using inline JSDoc?](https://stackoverflow.com/questions/5873927/how-to-indicate-param-is-optional-using-inline-jsdoc) – Icepickle Aug 06 '19 at 18:01
  • Next to the duplicate, you probably would describe the type for your second parameter – Icepickle Aug 06 '19 at 18:02
  • I don't believe this is a dupe, as it's not asking for the JSDoc to be inline. – bxk21 Aug 06 '19 at 19:19
  • 2
    I actually did look at the thread that is being claimed is a dup and indeed none of the answers address my question from what I can tell. Not only is it not inline I want, but it doesn't address the particular case of using the optional object param with various properties – theJuls Aug 06 '19 at 19:30
  • I'm using VSCode and have a similar JSDoc. It seems to be showing up correctly. What exactly 'doesn't seem right'? – bxk21 Aug 06 '19 at 19:31
  • It wasn't being shown correctly, basically was just giving me the `any` type. If this is the case, perhaps there was an issue with refreshing in time. Will give this a second check – theJuls Aug 06 '19 at 19:33

0 Answers0