Import style punditry (#36814)

This commit is contained in:
Andrew Branch
2020-02-14 15:57:30 -08:00
committed by GitHub
parent b82d3207e8
commit a2fe661e19
2 changed files with 5 additions and 1 deletions

View File

@@ -237,7 +237,9 @@ namespace ts.OrganizeImports {
? createNamedImports(sortedImportSpecifiers)
: updateNamedImports(namedImports[0].importClause!.namedBindings as NamedImports, sortedImportSpecifiers); // TODO: GH#18217
// Type-only imports are not allowed to combine
// Type-only imports are not allowed to mix default, namespace, and named imports in any combination.
// We could rewrite a default import as a named import (`import { default as name }`), but we currently
// choose not to as a stylistic preference.
if (isTypeOnly && newDefaultImport && newNamedImports) {
coalescedImports.push(
updateImportDeclarationAndClause(importDecl, newDefaultImport, /*namedBindings*/ undefined));

View File

@@ -186,6 +186,8 @@ namespace ts {
`import type { x } from "lib";`,
`import type * as y from "lib";`,
`import type z from "lib";`);
// Default import could be rewritten as a named import to combine with `x`,
// but seems of debatable merit.
const actualCoalescedImports = OrganizeImports.coalesceImports(sortedImports);
const expectedCoalescedImports = actualCoalescedImports;
assertListEqual(actualCoalescedImports, expectedCoalescedImports);