diff --git a/src/services/refactors/moveToNewFile.ts b/src/services/refactors/moveToNewFile.ts index 275ed16bd5a..ccd1a76f0d0 100644 --- a/src/services/refactors/moveToNewFile.ts +++ b/src/services/refactors/moveToNewFile.ts @@ -176,7 +176,7 @@ function getNewFileImportsAndAddExportInOldFile( if (hasSyntacticModifier(decl, ModifierFlags.Default)) { oldFileDefault = name; } - else { + else if (!oldFileNamedImports.includes (name.text)) { oldFileNamedImports.push(name.text); } } diff --git a/tests/cases/fourslash/moveToNewFile_overloads5.ts b/tests/cases/fourslash/moveToNewFile_overloads5.ts new file mode 100644 index 00000000000..3c6abd84227 --- /dev/null +++ b/tests/cases/fourslash/moveToNewFile_overloads5.ts @@ -0,0 +1,36 @@ +/// + +// @Filename: /a.ts +//// [|export function add(a: number, b: number): number; +//// export function add(a: string, b: string): string; +//// export function add(a: any, b: any): any { +//// multiply(2,3); +//// return a + b; +//// }|] +// +//// function multiply(x: number, y: number): number; +//// function multiply(x: string, y: string): string; +//// function multiply(x: any, y: any) { +//// return x + y; +//// } + +verify.moveToNewFile({ + newFileContents: { + "/a.ts": + `export function multiply(x: number, y: number): number; +export function multiply(x: string, y: string): string; +export function multiply(x: any, y: any) { + return x + y; +}`, + "/add.ts": +`import { multiply } from "./a"; + +export function add(a: number, b: number): number; +export function add(a: string, b: string): string; +export function add(a: any, b: any): any { + multiply(2, 3); + return a + b; +} +` + }, +});