Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion crates/oxc_formatter/src/utils/assignment_like.rs
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,13 @@ fn is_complex_type_arguments(type_arguments: &TSTypeParameterInstantiation) -> b
let is_first_argument_complex = ts_type_argument_list.first().is_some_and(|first_argument| {
matches!(
first_argument,
TSType::TSUnionType(_) | TSType::TSIntersectionType(_) | TSType::TSTypeLiteral(_)
TSType::TSUnionType(_)
| TSType::TSIntersectionType(_)
| TSType::TSTypeLiteral(_)
// TODO: This is not part of Prettier's logic, but it makes sense to consider mapped types as
// complex because it is the same as type literals in terms of structure.
// NOTE: Once the `will_break` logic is added, this will have to be revisited.
| TSType::TSMappedType(_)
)
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Type argument is a `TSMappedType`
const emitter = createGlobalEmitter<{
[key in Event["type"]]: Extract<Event, { type: key }>
}>()

// Type argument is a `TSTypeLiteral`
const emitter2 = createGlobalEmitter<{
longlonglonglongKey: Extract<Event, { type: key }>
}>()
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
source: crates/oxc_formatter/tests/fixtures/mod.rs
---
==================== Input ====================
// Type argument is a `TSMappedType`
const emitter = createGlobalEmitter<{
[key in Event["type"]]: Extract<Event, { type: key }>
}>()

// Type argument is a `TSTypeLiteral`
const emitter2 = createGlobalEmitter<{
longlonglonglongKey: Extract<Event, { type: key }>
}>()

==================== Output ====================
------------------
{ printWidth: 80 }
------------------
// Type argument is a `TSMappedType`
const emitter = createGlobalEmitter<{
[key in Event["type"]]: Extract<Event, { type: key }>;
}>();

// Type argument is a `TSTypeLiteral`
const emitter2 = createGlobalEmitter<{
longlonglonglongKey: Extract<Event, { type: key }>;
}>();

-------------------
{ printWidth: 100 }
-------------------
// Type argument is a `TSMappedType`
const emitter = createGlobalEmitter<{
[key in Event["type"]]: Extract<Event, { type: key }>;
}>();

// Type argument is a `TSTypeLiteral`
const emitter2 = createGlobalEmitter<{
longlonglonglongKey: Extract<Event, { type: key }>;
}>();

===================== End =====================
Loading