Skip to content

Commit a2fe661

Browse files
authored
Import style punditry (microsoft#36814)
1 parent b82d320 commit a2fe661

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/services/organizeImports.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,9 @@ namespace ts.OrganizeImports {
237237
? createNamedImports(sortedImportSpecifiers)
238238
: updateNamedImports(namedImports[0].importClause!.namedBindings as NamedImports, sortedImportSpecifiers); // TODO: GH#18217
239239

240-
// Type-only imports are not allowed to combine
240+
// Type-only imports are not allowed to mix default, namespace, and named imports in any combination.
241+
// We could rewrite a default import as a named import (`import { default as name }`), but we currently
242+
// choose not to as a stylistic preference.
241243
if (isTypeOnly && newDefaultImport && newNamedImports) {
242244
coalescedImports.push(
243245
updateImportDeclarationAndClause(importDecl, newDefaultImport, /*namedBindings*/ undefined));

src/testRunner/unittests/services/organizeImports.ts

+2
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ namespace ts {
186186
`import type { x } from "lib";`,
187187
`import type * as y from "lib";`,
188188
`import type z from "lib";`);
189+
// Default import could be rewritten as a named import to combine with `x`,
190+
// but seems of debatable merit.
189191
const actualCoalescedImports = OrganizeImports.coalesceImports(sortedImports);
190192
const expectedCoalescedImports = actualCoalescedImports;
191193
assertListEqual(actualCoalescedImports, expectedCoalescedImports);

0 commit comments

Comments
 (0)