Test:better error for wrong return token (: vs =>)

This commit is contained in:
Nathan Shively-Sanders
2017-07-11 10:16:35 -07:00
parent b6ad43d4a5
commit 3638ff19b3
3 changed files with 77 additions and 0 deletions
@@ -0,0 +1,37 @@
tests/cases/compiler/parseErrorIncorrectReturnToken.ts(2,17): error TS1005: ':' expected.
tests/cases/compiler/parseErrorIncorrectReturnToken.ts(4,22): error TS1005: '=>' expected.
tests/cases/compiler/parseErrorIncorrectReturnToken.ts(4,24): error TS2693: 'string' only refers to a type, but is being used as a value here.
tests/cases/compiler/parseErrorIncorrectReturnToken.ts(9,18): error TS1005: '{' expected.
tests/cases/compiler/parseErrorIncorrectReturnToken.ts(9,21): error TS2693: 'string' only refers to a type, but is being used as a value here.
tests/cases/compiler/parseErrorIncorrectReturnToken.ts(9,28): error TS1005: ';' expected.
tests/cases/compiler/parseErrorIncorrectReturnToken.ts(12,1): error TS1128: Declaration or statement expected.
==== tests/cases/compiler/parseErrorIncorrectReturnToken.ts (7 errors) ====
type F1 = {
(n: number) => string; // should be : not =>
~~
!!! error TS1005: ':' expected.
}
type F2 = (n: number): string; // should be => not :
~
!!! error TS1005: '=>' expected.
~~~~~~
!!! error TS2693: 'string' only refers to a type, but is being used as a value here.
// doesn't work in non-type contexts, where the return type is optional
let f = (n: number) => string => n.toString();
let o = {
m(n: number) => string {
~~
!!! error TS1005: '{' expected.
~~~~~~
!!! error TS2693: 'string' only refers to a type, but is being used as a value here.
~
!!! error TS1005: ';' expected.
return n.toString();
}
};
~
!!! error TS1128: Declaration or statement expected.
@@ -0,0 +1,27 @@
//// [parseErrorIncorrectReturnToken.ts]
type F1 = {
(n: number) => string; // should be : not =>
}
type F2 = (n: number): string; // should be => not :
// doesn't work in non-type contexts, where the return type is optional
let f = (n: number) => string => n.toString();
let o = {
m(n: number) => string {
return n.toString();
}
};
//// [parseErrorIncorrectReturnToken.js]
string; // should be => not :
// doesn't work in non-type contexts, where the return type is optional
var f = function (n) { return function (string) { return n.toString(); }; };
var o = {
m: function (n) { }
};
string;
{
return n.toString();
}
;
@@ -0,0 +1,13 @@
type F1 = {
(n: number) => string; // should be : not =>
}
type F2 = (n: number): string; // should be => not :
// doesn't work in non-type contexts, where the return type is optional
let f = (n: number) => string => n.toString();
let o = {
m(n: number) => string {
return n.toString();
}
};