Skip to content

Commit 92eedcb

Browse files
typescript-botDanielRosenwasser
andauthoredMar 19, 2025
🤖 Pick PR #61452 (Fix errors on type assertions in er...) into release-5.8 (#61453)
Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
1 parent 88a002a commit 92eedcb

File tree

6 files changed

+87
-2
lines changed

6 files changed

+87
-2
lines changed
 

‎src/compiler/checker.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -37315,8 +37315,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3731537315
grammarErrorOnNode(node, Diagnostics.This_syntax_is_reserved_in_files_with_the_mts_or_cts_extension_Use_an_as_expression_instead);
3731637316
}
3731737317
if (compilerOptions.erasableSyntaxOnly) {
37318-
const start = node.type.pos - "<".length;
37319-
const end = skipTrivia(file.text, node.type.end) + ">".length;
37318+
const start = skipTrivia(file.text, node.pos);
37319+
const end = node.expression.pos;
3732037320
diagnostics.add(createFileDiagnostic(file, start, end - start, Diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled));
3732137321
}
3732237322
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
index.ts(1,10): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
2+
index.ts(1,19): error TS1005: '>' expected.
3+
index.ts(2,9): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
4+
index.ts(2,18): error TS1005: '>' expected.
5+
index.ts(3,9): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
6+
index.ts(3,17): error TS1005: '>' expected.
7+
8+
9+
==== index.ts (6 errors) ====
10+
let a = (<unknown function foo() {});
11+
~~~~~~~~
12+
!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
13+
~~~~~~~~
14+
!!! error TS1005: '>' expected.
15+
let b = <unknown 123;
16+
~~~~~~~~
17+
!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
18+
~~~
19+
!!! error TS1005: '>' expected.
20+
let c = <unknown
21+
~~~~~~~~
22+
!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
23+
24+
!!! error TS1005: '>' expected.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//// [tests/cases/compiler/erasableSyntaxOnly2.ts] ////
2+
3+
//// [index.ts]
4+
let a = (<unknown function foo() {});
5+
let b = <unknown 123;
6+
let c = <unknown
7+
8+
//// [index.js]
9+
var a = function foo() { };
10+
var b = 123;
11+
var c = ;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//// [tests/cases/compiler/erasableSyntaxOnly2.ts] ////
2+
3+
=== index.ts ===
4+
let a = (<unknown function foo() {});
5+
>a : Symbol(a, Decl(index.ts, 0, 3))
6+
>foo : Symbol(foo, Decl(index.ts, 0, 17))
7+
8+
let b = <unknown 123;
9+
>b : Symbol(b, Decl(index.ts, 1, 3))
10+
11+
let c = <unknown
12+
>c : Symbol(c, Decl(index.ts, 2, 3))
13+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//// [tests/cases/compiler/erasableSyntaxOnly2.ts] ////
2+
3+
=== index.ts ===
4+
let a = (<unknown function foo() {});
5+
>a : unknown
6+
> : ^^^^^^^
7+
>(<unknown function foo() {}) : unknown
8+
> : ^^^^^^^
9+
><unknown function foo() {} : unknown
10+
> : ^^^^^^^
11+
>function foo() {} : () => void
12+
> : ^^^^^^^^^^
13+
>foo : () => void
14+
> : ^^^^^^^^^^
15+
16+
let b = <unknown 123;
17+
>b : unknown
18+
> : ^^^^^^^
19+
><unknown 123 : unknown
20+
> : ^^^^^^^
21+
>123 : 123
22+
> : ^^^
23+
24+
let c = <unknown
25+
>c : unknown
26+
> : ^^^^^^^
27+
><unknown : unknown
28+
> : ^^^^^^^
29+
> : any
30+
> : ^^^
31+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// @erasableSyntaxOnly: true
2+
3+
// @filename: index.ts
4+
let a = (<unknown function foo() {});
5+
let b = <unknown 123;
6+
let c = <unknown

0 commit comments

Comments
 (0)
Failed to load comments.