Skip to content

Improved const extraction for function expressions and arrow functions#32345

Merged
orta merged 2 commits intomicrosoft:masterfrom
dragomirtitian:GH-32325-improve-const-function-extraction
Sep 11, 2019
Merged

Improved const extraction for function expressions and arrow functions#32345
orta merged 2 commits intomicrosoft:masterfrom
dragomirtitian:GH-32325-improve-const-function-extraction

Conversation

@dragomirtitian
Copy link
Copy Markdown
Contributor

@dragomirtitian dragomirtitian commented Jul 11, 2019

The behavior applies if the function:

  • is contextually typed (because otherwise no type annotation for the variable would have been generated anyway)
  • is not generic
  • doesn't have parameters inferred as any

If these conditions are met, we add missing parameters type and we add this parameter to the function (if the function signature as a this parameter).

Fixes #32257

…s. The behavior applies if the function:

- is contextually typed (because otherwise no type annotation for the variable would have been generated anyway)
- is not generic
- doesn't have parameters inferred as any

If these conditions are met, we add missing parameters type and we add this parameter to the function.
@dragomirtitian
Copy link
Copy Markdown
Contributor Author

@RyanCavanaugh @DanielRosenwasser Not sure who to ping about this. If there is anything I can do to move this along let me know.

Copy link
Copy Markdown
Contributor

@orta orta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, this looks good to me. Sorry it took some time for me to come back round to get it.

The amount of comments made it much easier to grok, thanks! (Will merge after suggestion)

Comment thread src/services/refactors/extractSymbol.ts Outdated

// ==SCOPE::Extract to constant in enclosing scope==
const newLocal: (x: number, y: string) => void = (x, y) => x + y;
const newLocal = (x: number, y: string): string => x + y;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 🆗

Fixed typo in comment

Co-Authored-By: Orta <orta.therox+github@gmail.com>
@orta
Copy link
Copy Markdown
Contributor

orta commented Sep 11, 2019

Thanks, looks great.

@orta orta merged commit fb9b3fe into microsoft:master Sep 11, 2019
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Suggestion: "extract to constant" for function is too verbose

3 participants