microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.82k stars 12.46k forks source link

Add extract to parameter refactoring for JS/TS in vscode #37191

Open pauldambra opened 4 years ago

pauldambra commented 4 years ago

Search Terms

Suggestion

Add a refactoring to extract to parameter for JS/TS

e.g.

for


const fangler = () => {
  return {
    someProperty: [
      "a", "b"
    ]
  }
}

the extract to parameter refactoring would change to


const fangler = (secondItem) => {
  return {
    someProperty: [
      "a", secondItem
    ]
  }
}

and populate each existing call site with the extracted value (in this example "b")

Use Cases

It is a common refactoring when you discover that a previously fixed value should instead be provided by a caller

Examples

e.g. in the case where I went looking for it code in a Lambda function that created a fixed header had to start providing a varying value depending on context and the easiest refactoring was to extract the currently fixed value as a parameter so that the callers that would vary it could do without breaking other callers

see https://twitter.com/mattbierner/status/1234920525543002113

Checklist

My suggestion meets these guidelines:

iDschepe commented 1 year ago

Would love to see that feature! ❀️

Edit: Maybe also consider an additional refactoring case like "Introduce parameter object".