fix(43313): add parentheses to a type assertions (#43315)

This commit is contained in:
Oleksandr T
2021-03-31 01:29:02 +03:00
committed by GitHub
parent a8ee22f73d
commit 819651eb5f
3 changed files with 30 additions and 2 deletions

View File

@@ -2516,8 +2516,10 @@ namespace ts {
}
/* @internal */
export function needsParentheses(expression: Expression) {
return isBinaryExpression(expression) && expression.operatorToken.kind === SyntaxKind.CommaToken || isObjectLiteralExpression(expression);
export function needsParentheses(expression: Expression): boolean {
return isBinaryExpression(expression) && expression.operatorToken.kind === SyntaxKind.CommaToken
|| isObjectLiteralExpression(expression)
|| isAsExpression(expression) && isObjectLiteralExpression(expression.expression);
}
export function getContextualTypeFromParent(node: Expression, checker: TypeChecker): Type | undefined {

View File

@@ -0,0 +1,13 @@
/// <reference path='fourslash.ts' />
////const a = /*a*/()/*b*/ => {
//// return {} as {}
////};
goTo.select("a", "b");
edit.applyRefactor({
refactorName: "Add or remove braces in an arrow function",
actionName: "Remove braces from arrow function",
actionDescription: "Remove braces from arrow function",
newContent: `const a = () => ({} as {});`,
});

View File

@@ -0,0 +1,13 @@
/// <reference path='fourslash.ts' />
////const a = /*a*/()/*b*/ => {
//// return {} as object
////};
goTo.select("a", "b");
edit.applyRefactor({
refactorName: "Add or remove braces in an arrow function",
actionName: "Remove braces from arrow function",
actionDescription: "Remove braces from arrow function",
newContent: `const a = () => ({} as object);`,
});