Skip to content

Commit c8083db

Browse files
committed
Fixed an issue with type-only import promoting
1 parent fd390e7 commit c8083db

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

src/services/codefixes/importFixes.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,15 +1329,17 @@ function promoteFromTypeOnly(changes: textChanges.ChangeTracker, aliasDeclaratio
13291329
if (aliasDeclaration.isTypeOnly) {
13301330
const sortKind = OrganizeImports.detectImportSpecifierSorting(aliasDeclaration.parent.elements, preferences);
13311331
if (aliasDeclaration.parent.elements.length > 1 && sortKind) {
1332-
changes.delete(sourceFile, aliasDeclaration);
13331332
const newSpecifier = factory.updateImportSpecifier(aliasDeclaration, /*isTypeOnly*/ false, aliasDeclaration.propertyName, aliasDeclaration.name);
13341333
const comparer = OrganizeImports.getOrganizeImportsComparer(preferences, sortKind === SortKind.CaseInsensitive);
13351334
const insertionIndex = OrganizeImports.getImportSpecifierInsertionIndex(aliasDeclaration.parent.elements, newSpecifier, comparer);
1336-
changes.insertImportSpecifierAtIndex(sourceFile, newSpecifier, aliasDeclaration.parent, insertionIndex);
1337-
}
1338-
else {
1339-
changes.deleteRange(sourceFile, aliasDeclaration.getFirstToken()!);
1335+
if (aliasDeclaration.parent.elements.indexOf(aliasDeclaration) !== insertionIndex) {
1336+
changes.delete(sourceFile, aliasDeclaration);
1337+
changes.insertImportSpecifierAtIndex(sourceFile, newSpecifier, aliasDeclaration.parent, insertionIndex);
1338+
return aliasDeclaration;
1339+
}
1340+
13401341
}
1342+
changes.deleteRange(sourceFile, aliasDeclaration.getFirstToken()!);
13411343
return aliasDeclaration;
13421344
}
13431345
else {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/// <reference path="fourslash.ts" />
2+
// @module: es2015
3+
4+
// https://github.com/microsoft/TypeScript/issues/55363
5+
6+
// @Filename: index.ts
7+
//// import { TwistyAlgEditor, type TwistyPlayer } from "./other-file";
8+
//// new TwistyPlayer();
9+
10+
// @Filename: other-file.ts
11+
//// export class TwistyAlgEditor {}
12+
//// export class TwistyPlayer {}
13+
14+
verify.codeFix({
15+
index: 0,
16+
description: [ts.Diagnostics.Remove_type_from_import_of_0_from_1.message, "TwistyPlayer", "./other-file"],
17+
applyChanges: true,
18+
newFileContent:
19+
`import { TwistyAlgEditor, TwistyPlayer } from "./other-file";
20+
new TwistyPlayer();`
21+
})

0 commit comments

Comments
 (0)