fix(ts-formatter): handle logical expression parentheses in ts as expression
MODIFY
internal/formatter/node/parentheses.ts
internal/formatter/node/parentheses.ts
@@ -192,6 +192,11 @@ function needsParenLogicalExpression(
}
}
+ // (a || b) as type
+ if (parent.type === "TSAsExpression") {
+ return true;
+ }
+
if (isBinary(parent)) {
const parentOp = parent.operator;
const parentPos = getPrecedence(parentOp);

MODIFY
internal/formatter/test-fixtures/typescript/parentheses/asExpression/input.test.md
internal/formatter/test-fixtures/typescript/parentheses/asExpression/input.test.md
@@ -24,6 +24,7 @@ class Foo extends (Bar as any) {}
const bar = () => ({} as any);
(foo as any) as any;
const baz = async () => { await (foo as any); }
+const qux = (foo || bar) as any;
```
@@ -43,5 +44,6 @@ const bar = () => ({} as any);
const baz = async () => {
await (foo as any);
};
+const qux = (foo || bar) as any;
```

MODIFY
internal/formatter/test-fixtures/typescript/parentheses/asExpression/input.ts
internal/formatter/test-fixtures/typescript/parentheses/asExpression/input.ts
@@ -9,3 +9,4 @@ class Foo extends (Bar as any) {}
const bar = () => ({} as any);
(foo as any) as any;
const baz = async () => { await (foo as any); }
+const qux = (foo || bar) as any;

fix(ts-formatter): handle logical expression parentheses in ts as expression (#1411)