mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Test:better error for wrong return token (: vs =>)
This commit is contained in:
@@ -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();
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user