microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
101.15k stars 12.51k forks source link

Import named `Disposable` is not moved when moving code to another file #59799

Closed alexdima closed 4 days ago

alexdima commented 2 months ago
// @filename: src/_producer.ts
export class Disposable {}
// @filename: src/_consumer.ts
import { Disposable } from './_producer';

class Something extends Disposable {
}

Doing move to a new file on Something generates the following 🐛 (note how Disposable is not imported from _producer.ts):

// @filename: src/Something.ts
class Something extends Disposable {
}
iisaduan commented 2 months ago

Was this found in vscode, and if so, could you link the/a location in the repo where this happens? Currently, with the reported case, the import is correctly generated (#59884).

My guess is that this behavior is related to the autoImportFileExcludePatterns setting. I fixed a related crash few months ago (https://github.com/microsoft/TypeScript/pull/58537), and the default case, if we could not find a non-excluded file to import from, was to finish the rest of the codefix without generating that particular import.

alexdima commented 1 month ago

Appologies for the slow reply. I'm really sorry, I spent 20 minutes trying to reproduce in a separate project than vscode, but I did not manage (I tried bringing over the tsconfig from vscode, the settings from the vscode folder, but to no avail).

Here are the steps:

https://github.com/user-attachments/assets/41ec8198-ec4a-41d2-88c4-f2b005beb932

iisaduan commented 1 month ago

This looks like a name resolving bug, thanks for providing the repo location!