Skip to content

Commit 0876feb

Browse files
authored
fix(42160): omit unnecessary parentheses around assertions (#42169)
1 parent f1dca6a commit 0876feb

File tree

7 files changed

+50
-4
lines changed

7 files changed

+50
-4
lines changed

src/compiler/utilities.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3580,7 +3580,8 @@ namespace ts {
35803580
}
35813581

35823582
// TODO: Should prefix `++` and `--` be moved to the `Update` precedence?
3583-
// TODO: We are missing `TypeAssertionExpression`
3583+
case SyntaxKind.TypeAssertionExpression:
3584+
case SyntaxKind.NonNullExpression:
35843585
case SyntaxKind.PrefixUnaryExpression:
35853586
case SyntaxKind.TypeOfExpression:
35863587
case SyntaxKind.VoidExpression:
@@ -3602,6 +3603,9 @@ namespace ts {
36023603
case SyntaxKind.ElementAccessExpression:
36033604
return OperatorPrecedence.Member;
36043605

3606+
case SyntaxKind.AsExpression:
3607+
return OperatorPrecedence.Relational;
3608+
36053609
case SyntaxKind.ThisKeyword:
36063610
case SyntaxKind.SuperKeyword:
36073611
case SyntaxKind.Identifier:

tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_thenTypeArgument1.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function wrapResponse<T>(response: T): APIResponse<T> {
1919
}
2020

2121
async function get() {
22-
const response = await Promise.resolve((undefined!));
22+
const response = await Promise.resolve(undefined!);
2323
const result: APIResponse<{ email: string; }> = wrapResponse(response);
2424
return result;
2525
}

tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_thenTypeArgument2.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function wrapResponse<T>(response: T): APIResponse<T> {
1919
}
2020

2121
async function get() {
22-
const d = await Promise.resolve((undefined!));
22+
const d = await Promise.resolve(undefined!);
2323
const result: APIResponse<{ email: string; }> = wrapResponse(d);
2424
return result;
2525
}

tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_thenTypeArgument3.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function wrapResponse<T>(response: T): APIResponse<T> {
2222
}
2323

2424
async function get() {
25-
const d = await Promise.resolve((undefined!));
25+
const d = await Promise.resolve(undefined!);
2626
console.log(d);
2727
const result: APIResponse<{ email: string; }> = wrapResponse(d);
2828
return result;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @filename: foo.ts
4+
////const foo = /*a*/1!/*b*/;
5+
6+
goTo.select("a", "b");
7+
edit.applyRefactor({
8+
refactorName: "Extract Symbol",
9+
actionName: "constant_scope_0",
10+
actionDescription: "Extract to constant in enclosing scope",
11+
newContent:
12+
`const newLocal = 1!;
13+
const foo = /*RENAME*/newLocal;`
14+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @filename: foo.ts
4+
////const foo = /*a*/1 as number/*b*/;
5+
6+
goTo.select("a", "b");
7+
edit.applyRefactor({
8+
refactorName: "Extract Symbol",
9+
actionName: "constant_scope_0",
10+
actionDescription: "Extract to constant in enclosing scope",
11+
newContent:
12+
`const newLocal = 1 as number;
13+
const foo = /*RENAME*/newLocal;`
14+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @filename: foo.ts
4+
////const foo = /*a*/<number>1/*b*/;
5+
6+
goTo.select("a", "b");
7+
edit.applyRefactor({
8+
refactorName: "Extract Symbol",
9+
actionName: "constant_scope_0",
10+
actionDescription: "Extract to constant in enclosing scope",
11+
newContent:
12+
`const newLocal = <number>1;
13+
const foo = /*RENAME*/newLocal;`
14+
});

0 commit comments

Comments
 (0)