Skip to content

Commit 819651e

Browse files
authored
fix(43313): add parentheses to a type assertions (microsoft#43315)
1 parent a8ee22f commit 819651e

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

src/services/utilities.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -2516,8 +2516,10 @@ namespace ts {
25162516
}
25172517

25182518
/* @internal */
2519-
export function needsParentheses(expression: Expression) {
2520-
return isBinaryExpression(expression) && expression.operatorToken.kind === SyntaxKind.CommaToken || isObjectLiteralExpression(expression);
2519+
export function needsParentheses(expression: Expression): boolean {
2520+
return isBinaryExpression(expression) && expression.operatorToken.kind === SyntaxKind.CommaToken
2521+
|| isObjectLiteralExpression(expression)
2522+
|| isAsExpression(expression) && isObjectLiteralExpression(expression.expression);
25212523
}
25222524

25232525
export function getContextualTypeFromParent(node: Expression, checker: TypeChecker): Type | undefined {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////const a = /*a*/()/*b*/ => {
4+
//// return {} as {}
5+
////};
6+
7+
goTo.select("a", "b");
8+
edit.applyRefactor({
9+
refactorName: "Add or remove braces in an arrow function",
10+
actionName: "Remove braces from arrow function",
11+
actionDescription: "Remove braces from arrow function",
12+
newContent: `const a = () => ({} as {});`,
13+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////const a = /*a*/()/*b*/ => {
4+
//// return {} as object
5+
////};
6+
7+
goTo.select("a", "b");
8+
edit.applyRefactor({
9+
refactorName: "Add or remove braces in an arrow function",
10+
actionName: "Remove braces from arrow function",
11+
actionDescription: "Remove braces from arrow function",
12+
newContent: `const a = () => ({} as object);`,
13+
});

0 commit comments

Comments
 (0)