Return expressions always need to be type checked

This commit is contained in:
Jason Freeman 2015-06-02 17:33:57 -07:00
parent f83d54b18f
commit 46da6678ad
5 changed files with 22 additions and 1 deletions

View File

@ -7454,6 +7454,10 @@ module ts {
}
if (node.body) {
if (!node.type) {
getReturnTypeOfSignature(getSignatureFromDeclaration(node));
}
if (node.body.kind === SyntaxKind.Block) {
checkSourceElement(node.body);
}

View File

@ -1,12 +1,15 @@
tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts(1,1): error TS1108: A 'return' statement can only be used within a function body.
tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts(1,18): error TS2304: Cannot find name 'role'.
tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts(2,18): error TS2304: Cannot find name 'Role'.
tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts(4,26): error TS2503: Cannot find namespace 'ng'.
==== tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts (3 errors) ====
==== tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts (4 errors) ====
return this.edit(role)
~~~~~~
!!! error TS1108: A 'return' statement can only be used within a function body.
~~~~
!!! error TS2304: Cannot find name 'role'.
.then((role: Role) =>
~~~~
!!! error TS2304: Cannot find name 'Role'.

View File

@ -0,0 +1,7 @@
tests/cases/compiler/typeCheckReturnExpression.ts(1,11): error TS7011: Function expression, which lacks return-type annotation, implicitly has an 'any' return type.
==== tests/cases/compiler/typeCheckReturnExpression.ts (1 errors) ====
var foo = () => undefined;
~~~~~~~~~~~~~~~
!!! error TS7011: Function expression, which lacks return-type annotation, implicitly has an 'any' return type.

View File

@ -0,0 +1,5 @@
//// [typeCheckReturnExpression.ts]
var foo = () => undefined;
//// [typeCheckReturnExpression.js]
var foo = function () { return undefined; };

View File

@ -0,0 +1,2 @@
//@noImplicitAny: true
var foo = () => undefined;