mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-04-17 01:49:41 -05:00
Better error for wrong return (: vs =>) in types
It's very ambiguous in expression position, so impossible to give a
better message from the parser. For example:
let f = (x: number) => number => x + 1;
~~
Should be ':'
But the parser doesn't know that 'number' isn't an expression now.
This commit is contained in:
@@ -2231,6 +2231,16 @@ namespace ts {
|
||||
else if (parseOptional(returnToken)) {
|
||||
signature.type = parseTypeOrTypePredicate();
|
||||
}
|
||||
else if (context === SignatureContext.Type) {
|
||||
const start = scanner.getTokenPos();
|
||||
const length = scanner.getTextPos() - start;
|
||||
const backwardToken = parseOptional(returnToken === SyntaxKind.ColonToken ? SyntaxKind.EqualsGreaterThanToken : SyntaxKind.ColonToken);
|
||||
if (backwardToken) {
|
||||
// This is easy to get backward, especially in type contexts, so parse the type anyway
|
||||
signature.type = parseTypeOrTypePredicate();
|
||||
parseErrorAtPosition(start, length, Diagnostics._0_expected, tokenToString(returnToken));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function parseParameterList(context: SignatureContext) {
|
||||
|
||||
Reference in New Issue
Block a user