Skip to content

Destructure of function parameters - Refactoring #24827

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

Open
lukaszpolowczyk opened this issue Jun 9, 2018 · 7 comments
Open

Destructure of function parameters - Refactoring #24827

lukaszpolowczyk opened this issue Jun 9, 2018 · 7 comments
Labels
Domain: Refactorings e.g. extract to constant or function, rename symbol Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. Suggestion An idea for TypeScript

Comments

@lukaszpolowczyk
Copy link

lukaszpolowczyk commented Jun 9, 2018

const calllback = event=> {
   let {target} = event;
   // code with used target
}

to

const calllback = ({target})=> {
   // code with used target
}

Same in the opposite direction and with a more complex and deep destructure and function content.

@Shinigami92
Copy link

Shinigami92 commented Jun 9, 2018

But shouldn't it be event.target?

const calllback = event => {
   const target = event.target;
   // code with used target
}

to

const calllback = ({target}) => {
   // code with used target
}

@lukaszpolowczyk
Copy link
Author

@Shinigami92 Of course (May optionally be const {target} = event).
Sorry for the mistake.

@jcready
Copy link

jcready commented Jun 9, 2018

There's a big difference between your two examples though. In the first one target is a constant, but not in the second one. Destructured variables in function parameters can be reassigned.

@lukaszpolowczyk
Copy link
Author

@jcready Oh, I do not know why it seemed to me that it was different.
This somewhat limits this proposed refactoring function. : |

Actually, you can do it somehow? Or are there any standard plans for this?

@DanielRosenwasser DanielRosenwasser added Suggestion An idea for TypeScript Domain: Refactorings e.g. extract to constant or function, rename symbol labels Jun 9, 2018
@weswigham weswigham added Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. In Discussion Not yet reached consensus labels Nov 6, 2018
@RyanCavanaugh RyanCavanaugh removed In Discussion Not yet reached consensus labels Mar 7, 2019
@Kingwl
Copy link
Contributor

Kingwl commented Aug 24, 2020

Hi folks.
There's a similar refactor #39832 that do not convert at the original position but append new line below

@lukaszpolowczyk
Copy link
Author

@Kingwl What about function parameter destructure? And it looks like it works in one direction.

@Kingwl
Copy link
Contributor

Kingwl commented Aug 25, 2020

Well, It's good to take a try.

@Kingwl Kingwl mentioned this issue Sep 18, 2020
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: Refactorings e.g. extract to constant or function, rename symbol Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

7 participants