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

[Question] Documenting destructured function argument with rest parameter #2102

Open
minikN opened this issue Jan 11, 2024 · 0 comments
Open

Comments

@minikN
Copy link

minikN commented Jan 11, 2024

Hello,

Is it possible to correctly document something like this using JSDoc?

/**
 * CartFooter component
 *
 * @type {React.FunctionComponent}
 *
 * @param {Object} footerProps          props
 * @param {Object} footerProps.classes  classes injected from the parent
 * @param {Object} footerProps.events   events for the component
 * @param {Object} footerProps.children events for the component
 * @param {Object} footerProps.props
 * @param {React.Ref<Object>} ref
 * @returns {JSX.Element}
 * @constructor
 */
const CartFooter = ({ classes: parentClasses, events, children, ...props }, ref) => { /* ... */ }

I don't understand how to document the rest param ...props correctly in this case:

If I hover over ...props, VSCode describes it as

(parameter) props: {
    props: any;
}

Which is incorrect, if I do

const { a, b, ...options } = props
const { c, d } = options

Inside the function body, a, b, c and d have red lines, with the error Property 'q' does not exist on type '{ props: any; }'.ts(2339)

I don't understand why the type of ...props is { props: any; }. If I change

 * @param {Object} footerProps.props

to

 * @param {...any} footerProps.props

I get the error A rest parameter must be last in a parameter list.ts(1014).

I'd appreciate any help on this. Thanks

Environment

VSCode 1.85.1
TypeScript 5.3.3
JSDoc config:

{
  "tags": {
    "allowUnknownTags": true
  },
  "plugins": [
    "plugins/underscore",
    "plugins/escapeHtml",
    "plugins/markdown"
  ],
  "markdown": {
    "tags": ["todo"]
  },
  "source": {
    "include": ["./src"]
  },
  "templates": {
    "cleverLinks": true,
    "default": {
      "outputSourceFiles": true,
      "useLongnameInNav": true,
      "layoutFile" : "docs/template/layout.tmpl"
    }
  },
  "opts": {
    "encoding": "utf8",
    "destination": "./docs/generated",
    "recurse": true,
    "tutorials": "./docs/tutorials"
  }
}
@minikN minikN changed the title Documenting destructured function argument with rest parameter [Question] Documenting destructured function argument with rest parameter Jan 11, 2024
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

1 participant