Open
Description
π 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.