Skip to content

"Move to file" on global code unnecessarily imports/exports, generates invalid code #58801

@DanielRosenwasser

Description

@DanielRosenwasser
// main.ts

interface String {
    malkovich(): string;
}

[|String.prototype.malkovich = function (): string {
    return "malkovich";
}|]
  1. Select the range.
  2. Request "move to a new file"

Current

// newFile.ts
import { String } from "./strs";

String.prototype.malkovich = function (): string {
    return "malkovich";
};

// main.ts
export export export export export export export interface String {
    malkovich(): string;
}

export export export export export export 

Expected

// newFile.ts
String.prototype.malkovich = function (): string {
    return "malkovich";
};

// main.ts
interface String {
    malkovich(): string;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: LS: Refactoringse.g. extract to constant or function, rename symbolEffort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Help WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions