Skip to content

Refactor to convert variable to destructuring #25946

Closed
@ghost

Description

TypeScript Version: 3.1.0-dev.20180721

Code

function f() { return { x: 0, y: 1, z: 2 }; }
const p = f();
p.x;
p.y;
p.z;

Expected behavior:

After:

function f() { return { x: 0, y: 1, z: 2 }; }
const { x, y, z } = f();
x;
y;
z;

Note: I think it should generate { x, y, z } even if they're not all currently used (meaning, it should use every property declared in the return type of f). That way it's useful to perform this refactor immediately after writing the call to f(), before the result has been used.

Actual behavior:

No such refactor.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DeclinedThe issue was declined as something which matches the TypeScript visionDomain: Refactoringse.g. extract to constant or function, rename symbolSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions