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
How to document spread operator #1074
Comments
+1 |
2 similar comments
+1 |
+1 |
Also please see #1163 , seems like code with spread operator can't be even parsed by jsdoc currently. |
+2 |
How is this solved nowadays? |
works for me
|
See #987 and #1234 for examples of how to document this. I filed jsdoc/jsdoc.github.io#159 to add something about this to the docs. |
There is still no mention of the spread operator though, so I filed jsdoc/jsdoc.github.io#183 to add to the docs. |
I had a different need. I was doing my React component and I needed to document spread operator inside object destructuring. Seems that VSCode or JSDocs can not handle this properly. I tried this way: (I've simplified) /**
* @typedef {{ value: number }} MyObj
* @param {{ label?: string, rest: ...MyObj }} props
*/
const MyTextInput = ({ label, ...rest }) => { But "rest" gets the weird type I also tried this way: /**
* @typedef {{ value: number }} MyObj
* @param {{ label?: string, ...rest: MyObj }} props
*/
const MyTextInput = ({ label, ...rest }) => { But "rest" gets the weird type So I found a solution that works for now: /**
* @typedef {{ value: number }} MyObj
* @param {{ label?: string } & MyObj} props
*/
const MyTextInput = ({ label, ...rest }) => { This time, "rest" type is correctly assigned to an object with the properties of MyObj. |
if i have something like this: /**
* @param {function} successCallback
* @param {function} errorCallback
* @param {SessionRequest=} sessionRequest
*/
function requestSession (successCallback, errorCallback, sessionRequest) {
api.requestSession(successCallback, errorCallback, sessionRequest)
} and i would want to just write function request (...args) {
api.requestSession(...args)
} What would be the best way to write my jsdoc? |
Do correct me if I'm wrong but I think you could do: /**
* @param {function} successCallback
* @param {function} errorCallback
* @param {SessionRequest} sessionRequest
*/
function requestSession (...args) {
api.requestSession(...args)
} |
this will works, but the parameter name is fixed to indirect source: https://jsdoc.app/tags-type.html |
How do we document object spread operators in functions
The text was updated successfully, but these errors were encountered: