Skip to content

Commit c51439f

Browse files
committed
Don't Debug.fail on TypeAssertionExpression in JS
1 parent 6ead20d commit c51439f

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

src/compiler/program.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2930,13 +2930,12 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
29302930
diagnostics.push(createDiagnosticForNode(node, Diagnostics.Non_null_assertions_can_only_be_used_in_TypeScript_files));
29312931
return "skip";
29322932
case SyntaxKind.AsExpression:
2933+
case SyntaxKind.TypeAssertionExpression:
29332934
diagnostics.push(createDiagnosticForNode((node as AsExpression).type, Diagnostics.Type_assertion_expressions_can_only_be_used_in_TypeScript_files));
29342935
return "skip";
29352936
case SyntaxKind.SatisfiesExpression:
29362937
diagnostics.push(createDiagnosticForNode((node as SatisfiesExpression).type, Diagnostics.Type_satisfaction_expressions_can_only_be_used_in_TypeScript_files));
29372938
return "skip";
2938-
case SyntaxKind.TypeAssertionExpression:
2939-
Debug.fail(); // Won't parse these in a JS file anyway, as they are interpreted as JSX.
29402939
}
29412940
}
29422941

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
tests/cases/compiler/index.js(2,18): error TS2352: Conversion of type 'string' to type 'number' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
2+
tests/cases/compiler/index.js(2,18): error TS2703: The operand of a 'delete' operator must be a property reference.
3+
tests/cases/compiler/index.js(2,19): error TS8016: Type assertion expressions can only be used in TypeScript files.
4+
5+
6+
==== tests/cases/compiler/index.js (3 errors) ====
7+
const x = "oops";
8+
const y = delete <number> x;
9+
~~~~~~~~~~
10+
!!! error TS2352: Conversion of type 'string' to type 'number' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
11+
~~~~~~~~~~
12+
!!! error TS2703: The operand of a 'delete' operator must be a property reference.
13+
~~~~~~
14+
!!! error TS8016: Type assertion expressions can only be used in TypeScript files.
15+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== tests/cases/compiler/index.js ===
2+
const x = "oops";
3+
>x : Symbol(x, Decl(index.js, 0, 5))
4+
5+
const y = delete <number> x;
6+
>y : Symbol(y, Decl(index.js, 1, 5))
7+
>x : Symbol(x, Decl(index.js, 0, 5))
8+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
=== tests/cases/compiler/index.js ===
2+
const x = "oops";
3+
>x : "oops"
4+
>"oops" : "oops"
5+
6+
const y = delete <number> x;
7+
>y : boolean
8+
>delete <number> x : boolean
9+
><number> x : number
10+
>x : "oops"
11+

0 commit comments

Comments
 (0)