mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-10 18:04:18 -05:00
Fixed an issue with type-only import promoting (#55365)
This commit is contained in:
committed by
GitHub
parent
70b7de11fb
commit
0464e91c8b
@@ -1363,15 +1363,16 @@ function promoteFromTypeOnly(changes: textChanges.ChangeTracker, aliasDeclaratio
|
||||
if (aliasDeclaration.isTypeOnly) {
|
||||
const sortKind = OrganizeImports.detectImportSpecifierSorting(aliasDeclaration.parent.elements, preferences);
|
||||
if (aliasDeclaration.parent.elements.length > 1 && sortKind) {
|
||||
changes.delete(sourceFile, aliasDeclaration);
|
||||
const newSpecifier = factory.updateImportSpecifier(aliasDeclaration, /*isTypeOnly*/ false, aliasDeclaration.propertyName, aliasDeclaration.name);
|
||||
const comparer = OrganizeImports.getOrganizeImportsComparer(preferences, sortKind === SortKind.CaseInsensitive);
|
||||
const insertionIndex = OrganizeImports.getImportSpecifierInsertionIndex(aliasDeclaration.parent.elements, newSpecifier, comparer);
|
||||
changes.insertImportSpecifierAtIndex(sourceFile, newSpecifier, aliasDeclaration.parent, insertionIndex);
|
||||
}
|
||||
else {
|
||||
changes.deleteRange(sourceFile, aliasDeclaration.getFirstToken()!);
|
||||
if (aliasDeclaration.parent.elements.indexOf(aliasDeclaration) !== insertionIndex) {
|
||||
changes.delete(sourceFile, aliasDeclaration);
|
||||
changes.insertImportSpecifierAtIndex(sourceFile, newSpecifier, aliasDeclaration.parent, insertionIndex);
|
||||
return aliasDeclaration;
|
||||
}
|
||||
}
|
||||
changes.deleteRange(sourceFile, aliasDeclaration.getFirstToken()!);
|
||||
return aliasDeclaration;
|
||||
}
|
||||
else {
|
||||
|
||||
21
tests/cases/fourslash/codeFixPromoteTypeOnly1.ts
Normal file
21
tests/cases/fourslash/codeFixPromoteTypeOnly1.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
// @module: es2015
|
||||
|
||||
// https://github.com/microsoft/TypeScript/issues/55363
|
||||
|
||||
// @Filename: index.ts
|
||||
//// import { TwistyAlgEditor, type TwistyPlayer } from "./other-file";
|
||||
//// new TwistyPlayer();
|
||||
|
||||
// @Filename: other-file.ts
|
||||
//// export class TwistyAlgEditor {}
|
||||
//// export class TwistyPlayer {}
|
||||
|
||||
verify.codeFix({
|
||||
index: 0,
|
||||
description: [ts.Diagnostics.Remove_type_from_import_of_0_from_1.message, "TwistyPlayer", "./other-file"],
|
||||
applyChanges: true,
|
||||
newFileContent:
|
||||
`import { TwistyAlgEditor, TwistyPlayer } from "./other-file";
|
||||
new TwistyPlayer();`
|
||||
})
|
||||
Reference in New Issue
Block a user