Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Extract to function" refactor is not suggested if selection contains if statement (conditional return) #39640

Open
OliverJAsh opened this issue Jul 17, 2020 · 0 comments
Labels
Experience Enhancement Noncontroversial enhancements Suggestion An idea for TypeScript
Milestone

Comments

@OliverJAsh
Copy link
Contributor

OliverJAsh commented Jul 17, 2020

TypeScript Version: 3.9.2

Search Terms:

Code

const fn = ({ condition }: { condition: boolean }) => {
    if (condition) {
        return 1;
    } else {
        return 2;
    }
};

Select the whole if statement, including the else, like this:

image

Expected behavior:

The "extract to function" refactor should be suggested. When the refactor is used, it should produce code that looks like this:

const fn = ({ condition }: { condition: boolean }) => {
    return newFunction(condition);
};
function newFunction(condition: boolean) {
    if (condition) {
        return 1;
    } else {
        return 2;
    }
}

Actual behavior:

The "extract to function" refactor is not suggested (testing in VS Code).

Playground Link:

Related Issues:

@RyanCavanaugh RyanCavanaugh added Experience Enhancement Noncontroversial enhancements Suggestion An idea for TypeScript labels Jul 17, 2020
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Jul 17, 2020
@OliverJAsh OliverJAsh changed the title "Extract to function" refactor is not suggested if selection contains if statement "Extract to function" refactor is not suggested if selection contains if statement (conditional return) May 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Experience Enhancement Noncontroversial enhancements Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants