diff --git a/crates/oxc_formatter/src/parentheses/expression.rs b/crates/oxc_formatter/src/parentheses/expression.rs index 9afb6c45751bc..881fbdb50d964 100644 --- a/crates/oxc_formatter/src/parentheses/expression.rs +++ b/crates/oxc_formatter/src/parentheses/expression.rs @@ -738,8 +738,7 @@ impl NeedsParentheses<'_> for AstNode<'_, TSTypeAssertion<'_>> { fn type_cast_like_needs_parens(span: Span, parent: &AstNodes<'_>) -> bool { #[expect(clippy::match_same_arms)] // for better readability match parent { - AstNodes::ExportDefaultDeclaration(_) - | AstNodes::TSTypeAssertion(_) + AstNodes::TSTypeAssertion(_) | AstNodes::UnaryExpression(_) | AstNodes::AwaitExpression(_) | AstNodes::TSNonNullExpression(_) diff --git a/crates/oxc_formatter/tests/fixtures/ts/parenthesis/type-assertion.ts b/crates/oxc_formatter/tests/fixtures/ts/parenthesis/type-assertion.ts new file mode 100644 index 0000000000000..a5bee976165a0 --- /dev/null +++ b/crates/oxc_formatter/tests/fixtures/ts/parenthesis/type-assertion.ts @@ -0,0 +1 @@ +export default []; diff --git a/crates/oxc_formatter/tests/fixtures/ts/parenthesis/type-assertion.ts.snap b/crates/oxc_formatter/tests/fixtures/ts/parenthesis/type-assertion.ts.snap new file mode 100644 index 0000000000000..8119f71f80d43 --- /dev/null +++ b/crates/oxc_formatter/tests/fixtures/ts/parenthesis/type-assertion.ts.snap @@ -0,0 +1,18 @@ +--- +source: crates/oxc_formatter/tests/fixtures/mod.rs +--- +==================== Input ==================== +export default []; + +==================== Output ==================== +------------------ +{ printWidth: 80 } +------------------ +export default []; + +------------------- +{ printWidth: 100 } +------------------- +export default []; + +===================== End =====================