Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSDoc for destructurings #987

Closed
AlexanderZeilmann opened this issue Apr 16, 2015 · 7 comments
Closed

JSDoc for destructurings #987

AlexanderZeilmann opened this issue Apr 16, 2015 · 7 comments

Comments

@AlexanderZeilmann
Copy link

This is more a question/feature request than a bug report. In ES2015 it is possible to do destructurings directly in the arguments of a function. For example:

var fn = function ({prop1, prop2}) {
  // Do something with prop1 and prop2
}

// fn is called like this
fn({prop1: 1, prop2: 2});

How should the function fn be annotated with JSDoc comments?

I found the following on the documentation page for param tags:

The @param tag requires you to specify the name of the parameter you are documenting.

But I my case, the parameter has no name, so it is impossible for me to specify the parameter name...

@hegemonic
Copy link
Contributor

You can just give the object a fake name and document its properties, like this:

/**
 * My cool function.
 *
 * @param {Object} obj - An object.
 * @param {string} obj.prop1 - Property 1.
 * @param {string} obj.prop2 - Property 2.
 */
var fn = function ({prop1, prop2}) {
  // Do something with prop1 and prop2
}

@AlexanderZeilmann
Copy link
Author

@hegemonic thanks for the quick answer :-)

Hmm, the solution feels a little bit like a hack. But I agree, that is probably the best backwards compatible way to do this.

You might want add this case to the documentation.

@qfox
Copy link

qfox commented Aug 21, 2015

Sorry for the posting to closed issue but just look:

class ServerResponsePage {
  /**
   * @param {string} action - response name.
   * @param {string} result - response result.
   */
  constructor({query: {action, result}}) {
    // ...
  }
}

If we go the usual way it will be:

/**
 * @param {Object} opts
 * @param {Object} opts.query
 * @param {string} opts.query.action - desc
 * @param {string} opts.query.result - desc
 */

And it's noisy as hell.

Would be great if we can rethink this.

/cc @blazkovicz

@robcolburn
Copy link

@hegemonic's #987 (comment) is consistent w/ esdoc esdoc/esdoc#178

As far as I can tell, it's not documented though. Perhaps, we can be more explicit / borrow from esdoc?

https://esdoc.org/tags.html#object

@lll000111
Copy link

lll000111 commented May 8, 2017

Just for reference, the URL to esdoc documentation posted by @robcolburn just above seems to have changed:

https://esdoc.org/manual/tags.html#object

@hegemonic
Copy link
Contributor

I filed jsdoc/jsdoc.github.io#159 to add an example of this to the docs.

@dandv
Copy link
Contributor

dandv commented Nov 23, 2018

For the record, this is now documented at http://usejsdoc.org/tags-param.html#parameters-with-properties

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants