mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-18 17:27:54 -05:00
Import style punditry (#36814)
This commit is contained in:
@@ -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));
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user