Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4dc677b

Browse filesBrowse files
Fix errors on type assertions in erasableSyntaxOnly (#61452)
1 parent ee3dd72 commit 4dc677b
Copy full SHA for 4dc677b

File tree

6 files changed

+87
-2
lines changed
Filter options

6 files changed

+87
-2
lines changed

‎src/compiler/checker.ts

Copy file name to clipboardExpand all lines: src/compiler/checker.ts
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37316,8 +37316,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3731637316
grammarErrorOnNode(node, Diagnostics.This_syntax_is_reserved_in_files_with_the_mts_or_cts_extension_Use_an_as_expression_instead);
3731737317
}
3731837318
if (compilerOptions.erasableSyntaxOnly) {
37319-
const start = node.type.pos - "<".length;
37320-
const end = skipTrivia(file.text, node.type.end) + ">".length;
37319+
const start = skipTrivia(file.text, node.pos);
37320+
const end = node.expression.pos;
3732137321
diagnostics.add(createFileDiagnostic(file, start, end - start, Diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled));
3732237322
}
3732337323
}
+24Lines changed: 24 additions & 0 deletions
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.
+11Lines changed: 11 additions & 0 deletions
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 = ;
+13Lines changed: 13 additions & 0 deletions
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+
+31Lines changed: 31 additions & 0 deletions
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+
+6Lines changed: 6 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.