-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Preserve comments with object destructuring assignment #32392
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
Comments
I also noticed that the following does not get me comments, interface MyInterface {
/**
* I am x
*/
x : number;
/**
* I am y
*/
y : number;
}
function foo (
{
/**
* Additional comments about x
*/
x,
/**
* Additional comments about y
*/
y,
} : MyInterface
) {
/**
* Expected tooltip to have comment,
* > Additional comments aout x
* > I am x
*
* Actual: No comment
*/
x;
/**
* Expected tooltip to have comment,
* > Additional comments aout y
* > I am y
*
* Actual: No comment
*/
y;
} |
I disagree that it's expected. If you wrote the desugared version const x = someObj.x; there would (I think?) be no expectation of the comments transferring over. |
I guess you make a good point. It's just that I saw object destructuring assignment as sugar for reading What about I feel like I don't have the same expectation of the desugared version because it's possible for the variable to have a different name from the property. But with the sugared version, they'd have the same name. Unless they do Hmmm... I guess my request now is to have comments carry over if the variable has the same name as the property. And to not carry over if they're different. I hope I'm not the only one that would like this =( I feel like if they have the same name, they probably have the same "overall meaning"; like what the variable is describing |
Let's take react hooks as an example. I have a hook called const MyComponent: React.FC = () => {
const {bind, onSubmit} = useForm({name: ''})
// Rest of component
} In this situation any JSDoc comments for If the typings are passed over why is the documentation not? I have an example on the playground that shows what I mean. I get that these are the same: const x = someObject.x
const {x} = someObject but I would have said in both instances I would expect the documentation to copy over. |
Same issue, mybe new feature request. DescriptionProperty comments and type display on mouse hover Example/** My Mac App Gallery */
interface MyMac {
/** My Editor */
editor: string
/** My Browser */
browser: string
}
const myNewMac: MyMac = {
/** My Editor */
editor: 'VS Code',
/** My browser */
browser: 'Edge',
};
myNewMac.editor;
myNewMac.browser;
const { editor } = myNewMac;
console.log('My editor name:', editor); Screenshot |
There should be a way to document/annotate the destructured variables themselves. It should work with the JsDoc comment syntax shown in this Stack Overflow answer: interface Example {
/** interface property doc */
foo: string;
}
const example: Example = {foo: 'bar'};
const {
/** variable doc */
foo
} = example;
console.log(foo); When hovering over the |
is there any progress, please? |
Yes, please. This is frustrating to not have IntelliSense comments available on a destructured property. Across multiple frameworks, destructuring an imported composable is a very common pattern, and despite those properties having IntelliSense where they are used within your component, in the actual destructuring, there's nothing available. Example:
|
Search Terms
object destructuring assignment, comment
Suggestion
Playground
Use Cases
I came across this idea after writing code like this,
And I was hazy on the details of what each property was for.
So, I hovered my cursor over the variables
somePropertyA, somePropertyB, somePropertyC
and noticed there were no comments.I had to go to the declaration of
somePropertyA, somePropertyB, somePropertyC
and look at each property individually.At the moment, the way to get comments is to just do,
Then the tooltip for
o.somePropertyA, o.somePropertyB, o.somePropertyC
will have commentsExamples
See above suggestion
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: