Skip to content

moveToFile does not combine imports Β #57257

Open
@iisaduan

Description

@iisaduan

πŸ”Ž Search Terms

moveToFile, multiple auto imports, import order

πŸ•— Version & Regression Information

This is the behavior in every version I tried

⏯ Playground Link

No playground for moveToFile

πŸ’» Code

// @Filename: /bar.ts
import { a, z } from './a';
const q = 0;
// @Filename: /a.ts
import { } from './other';
import type { } from './other';

export const p = 0;
export const b = 1;
export const a = 2;
export const z = 3;
[|const y = p + b;|]

Move the selection in a.ts to bar.ts

πŸ™ Actual behavior

A separate import statement is generated.

//// @Filename: /bar.ts
import { p, b } from './a';
import { a, z } from './a';
const q = 0;
const y = p + b;

πŸ™‚ Expected behavior

The named imports should combine into one statement:Β 

// @Filename: /bar.ts
import { a, b, p, z } from './a';
const q = 0;
const y = p + b;

Additional information about the issue

I found this while working with auto-imports and playing with actions that generate multiple imports. The ideal order of imports should be a, b, p, z, as the imports in the original file were sorted. From #33839 (comment), and the current behavior of the add all missing imports codefix, p, b should be generated only if the original imports are not sorted.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions