Skip to content

'extract to function' for variable that is assigned in switch #33362

@mjbvz

Description

@mjbvz

TypeScript Version: [email protected]

Search Terms:

  • refactor
  • extract

Code

let value: string;
switch (Date.now()) {
    case 1:
        value = 'one';
        break;
    default:
        value = 'other';
        break;
}

console.log(value);

Select everything from let value to the end of the switch statement

Expected behavior:
A refactoring for extract to function is offered. It should change the code to something like:

let value = newFunction();

console.log(value);

function newFunction() {
    let value: string;
    switch (Date.now()) {
        case 1:
            value = 'one';
            break;
        default:
            value = 'other';
            break;
    }
    return value;
}

Actual behavior:
No refactoring offered

Playground Link:

Related Issues:

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: LS: Refactoringse.g. extract to constant or function, rename symbolFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions