Skip to content

"Extract to inner function" refactoring not available inside function expressionΒ #44110

Closed
@OliverJAsh

Description

@OliverJAsh

Bug Report

πŸ”Ž Search Terms

vs code quick fix refactoring code action arrow anonymous function

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about refactorings

⏯ Playground Link

N/A

πŸ’» Code

const fn1 = () => {
    const x = 1;
    const y = x + 1;
};

const fn2 = function () {
    const x = 1;
    const y = x + 1;
};
  1. Select the line that includes const y in either of the above function expressions
  2. Try to find and run the "extract to inner function" refactoring

πŸ™ Actual behavior

The "extract to inner function" refactoring is not listed.

πŸ™‚ Expected behavior

The "extract to inner function" refactoring is listed and produces this code:

const fn1 = () => {
    const x = 1;
    const y = newFunction();

    function newFunction() {
        return x + 1;
    }
};

const fn2 = function () {
    const x = 1;
    const y = newFunction();

    function newFunction() {
        return x + 1;
    }
};

Note: ideally it would produce arrow functions but that's a separate issue: #31860


It seems this refactoring is only available inside of function declarations. Is there a reason for this?

function fn0() {
    const x = 1;
    const y = x + 1;
}

This produces:

function fn0() {
    const x = 1;
    const y = newFunction();

    function newFunction() {
        return x + 1;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: Refactoringse.g. extract to constant or function, rename symbolHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions