Skip to content

Commit 3638ff1

Browse files
committed
Test:better error for wrong return token (: vs =>)
1 parent b6ad43d commit 3638ff1

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
tests/cases/compiler/parseErrorIncorrectReturnToken.ts(2,17): error TS1005: ':' expected.
2+
tests/cases/compiler/parseErrorIncorrectReturnToken.ts(4,22): error TS1005: '=>' expected.
3+
tests/cases/compiler/parseErrorIncorrectReturnToken.ts(4,24): error TS2693: 'string' only refers to a type, but is being used as a value here.
4+
tests/cases/compiler/parseErrorIncorrectReturnToken.ts(9,18): error TS1005: '{' expected.
5+
tests/cases/compiler/parseErrorIncorrectReturnToken.ts(9,21): error TS2693: 'string' only refers to a type, but is being used as a value here.
6+
tests/cases/compiler/parseErrorIncorrectReturnToken.ts(9,28): error TS1005: ';' expected.
7+
tests/cases/compiler/parseErrorIncorrectReturnToken.ts(12,1): error TS1128: Declaration or statement expected.
8+
9+
10+
==== tests/cases/compiler/parseErrorIncorrectReturnToken.ts (7 errors) ====
11+
type F1 = {
12+
(n: number) => string; // should be : not =>
13+
~~
14+
!!! error TS1005: ':' expected.
15+
}
16+
type F2 = (n: number): string; // should be => not :
17+
~
18+
!!! error TS1005: '=>' expected.
19+
~~~~~~
20+
!!! error TS2693: 'string' only refers to a type, but is being used as a value here.
21+
22+
// doesn't work in non-type contexts, where the return type is optional
23+
let f = (n: number) => string => n.toString();
24+
let o = {
25+
m(n: number) => string {
26+
~~
27+
!!! error TS1005: '{' expected.
28+
~~~~~~
29+
!!! error TS2693: 'string' only refers to a type, but is being used as a value here.
30+
~
31+
!!! error TS1005: ';' expected.
32+
return n.toString();
33+
}
34+
};
35+
~
36+
!!! error TS1128: Declaration or statement expected.
37+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//// [parseErrorIncorrectReturnToken.ts]
2+
type F1 = {
3+
(n: number) => string; // should be : not =>
4+
}
5+
type F2 = (n: number): string; // should be => not :
6+
7+
// doesn't work in non-type contexts, where the return type is optional
8+
let f = (n: number) => string => n.toString();
9+
let o = {
10+
m(n: number) => string {
11+
return n.toString();
12+
}
13+
};
14+
15+
16+
//// [parseErrorIncorrectReturnToken.js]
17+
string; // should be => not :
18+
// doesn't work in non-type contexts, where the return type is optional
19+
var f = function (n) { return function (string) { return n.toString(); }; };
20+
var o = {
21+
m: function (n) { }
22+
};
23+
string;
24+
{
25+
return n.toString();
26+
}
27+
;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
type F1 = {
3+
(n: number) => string; // should be : not =>
4+
}
5+
type F2 = (n: number): string; // should be => not :
6+
7+
// doesn't work in non-type contexts, where the return type is optional
8+
let f = (n: number) => string => n.toString();
9+
let o = {
10+
m(n: number) => string {
11+
return n.toString();
12+
}
13+
};

0 commit comments

Comments
 (0)