Skip to content

Commit 9881c99

Browse files
authored
fix(48544): allow to convert default exports to names for import type nodes (microsoft#48550)
1 parent 50a5bc8 commit 9881c99

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

src/services/findAllReferences.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1193,10 +1193,15 @@ namespace ts.FindAllReferences {
11931193
cb: (ref: Identifier) => void,
11941194
): void {
11951195
const importTracker = createImportTracker(sourceFiles, new Set(sourceFiles.map(f => f.fileName)), checker, cancellationToken);
1196-
const { importSearches, indirectUsers } = importTracker(exportSymbol, { exportKind: isDefaultExport ? ExportKind.Default : ExportKind.Named, exportingModuleSymbol }, /*isForRename*/ false);
1196+
const { importSearches, indirectUsers, singleReferences } = importTracker(exportSymbol, { exportKind: isDefaultExport ? ExportKind.Default : ExportKind.Named, exportingModuleSymbol }, /*isForRename*/ false);
11971197
for (const [importLocation] of importSearches) {
11981198
cb(importLocation);
11991199
}
1200+
for (const singleReference of singleReferences) {
1201+
if (isIdentifier(singleReference) && isImportTypeNode(singleReference.parent)) {
1202+
cb(singleReference);
1203+
}
1204+
}
12001205
for (const indirectUser of indirectUsers) {
12011206
for (const node of getPossibleSymbolReferenceNodes(indirectUser, isDefaultExport ? "default" : exportName)) {
12021207
// Import specifiers should be handled by importSearches

src/services/refactors/convertExport.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ namespace ts.refactor {
212212
}
213213
break;
214214
}
215+
case SyntaxKind.ImportType:
216+
const importTypeNode = parent as ImportTypeNode;
217+
changes.replaceNode(importingSourceFile, parent, factory.createImportTypeNode(importTypeNode.argument, factory.createIdentifier(exportName), importTypeNode.typeArguments, importTypeNode.isTypeOf));
218+
break;
215219
default:
216220
Debug.failBadSyntaxKind(parent);
217221
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @Filename: /a.ts
4+
/////*a*/export default class A {}/*b*/
5+
6+
// @Filename: /b.ts
7+
////export type A = typeof import("./a").default;
8+
9+
goTo.select("a", "b");
10+
edit.applyRefactor({
11+
refactorName: "Convert export",
12+
actionName: "Convert default export to named export",
13+
actionDescription: "Convert default export to named export",
14+
newContent: {
15+
"/a.ts": "export class A {}",
16+
"/b.ts": "export type A = typeof import(\"./a\").A;"
17+
},
18+
});

0 commit comments

Comments
 (0)