Skip to content

Destructure of function parameters - Refactoring #24827

Open

Description

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.

Activity

  1. Shinigami92 commented on Jun 9, 2018

    @Shinigami92

    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
    }
  2. lukaszpolowczyk commented on Jun 9, 2018

    @lukaszpolowczyk
    Author

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

  3. jcready commented on Jun 9, 2018

    @jcready

    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.

  4. lukaszpolowczyk commented on Jun 9, 2018

    @lukaszpolowczyk
    Author

    James Wyatt Cready-Pyle (@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?

  5. added
    Needs ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.
    on Nov 6, 2018
  6. Kingwl commented on Aug 24, 2020

    @Kingwl
    Contributor

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

  7. lukaszpolowczyk commented on Aug 24, 2020

    @lukaszpolowczyk
    Author

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

  8. Kingwl commented on Aug 25, 2020

    @Kingwl
    Contributor

    Well, It's good to take a try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Domain: LS: Refactoringse.g. extract to constant or function, rename symbolNeeds ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.SuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions