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
6 changes: 4 additions & 2 deletions crates/oxc_formatter/src/parentheses/ts_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ fn function_like_type_needs_parentheses<'a>(
}
false
}
AstNodes::TSUnionType(_) | AstNodes::TSIntersectionType(_) => true,
AstNodes::TSUnionType(union) => union.types.len() > 1,
AstNodes::TSIntersectionType(intersection) => intersection.types.len() > 1,
_ => operator_type_or_higher_needs_parens(span, parent),
}
}
Expand Down Expand Up @@ -142,7 +143,8 @@ impl<'a> NeedsParentheses<'a> for AstNode<'a, TSConditionalType<'a>> {
AstNodes::TSConditionalType(ty) => {
ty.extends_type().span() == self.span() || ty.check_type().span() == self.span()
}
AstNodes::TSUnionType(_) | AstNodes::TSIntersectionType(_) => true,
AstNodes::TSUnionType(union) => union.types.len() > 1,
AstNodes::TSIntersectionType(intersection) => intersection.types.len() > 1,
_ => operator_type_or_higher_needs_parens(self.span, self.parent),
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/oxc_formatter/tests/fixtures/ts/union/parenthesis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type T1<B> = | (B extends any ? number : string);
type T2 = | (() => void);
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
source: crates/oxc_formatter/tests/fixtures/mod.rs
---
==================== Input ====================
type T1<B> = | (B extends any ? number : string);
type T2 = | (() => void);

==================== Output ====================
type T1<B> = B extends any ? number : string;
type T2 = () => void;

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