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

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

Closed
DanielRosenwasser opened this issue Jun 7, 2024 · 3 comments · Fixed by #58811
Closed
Labels
Bug A bug in TypeScript Domain: Refactorings e.g. extract to constant or function, rename symbol Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Help Wanted You can do this

Comments

@DanielRosenwasser
Copy link
Member

// 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;
}
@DanielRosenwasser DanielRosenwasser added Bug A bug in TypeScript Domain: Refactorings e.g. extract to constant or function, rename symbol labels Jun 7, 2024
@fatcerberus
Copy link

fatcerberus commented Jun 7, 2024

Wait, it really produces long strings of export keywords like that? What the heck.

@nick-fallon
Copy link

nick-fallon commented Jun 10, 2024

This is very specific to Visual Studio Code dropdown menus. This cannot be reproduced as specified on other IDEs, such as Intellij/JetBrains.

In JetBrains, instead of the dropdown saying "Move to a new file", it says, "Move class '<class-name> to file <class-name>.ts'"

So, it seems to tie in to how the IDE is refactoring things.

@DanielRosenwasser
Copy link
Member Author

The logic is provided from TypeScript's language server. It is possible that this is an issue with VS Code, but I don't see any evidence of that yet. It is more likely that JetBrains is providing its own refactorings that are not powered by our language service.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Refactorings e.g. extract to constant or function, rename symbol Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Help Wanted You can do this
Projects
None yet
3 participants