mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-16 07:13:45 -05:00
Merge pull request #3352 from Microsoft/checkFunctionReturnExpression
Always check return expressions when type checking a file
This commit is contained in:
@@ -7657,6 +7657,15 @@ module ts {
|
||||
}
|
||||
|
||||
if (node.body) {
|
||||
if (!node.type) {
|
||||
// There are some checks that are only performed in getReturnTypeFromBody, that may produce errors
|
||||
// we need. An example is the noImplicitAny errors resulting from widening the return expression
|
||||
// of a function. Because checking of function expression bodies is deferred, there was never an
|
||||
// appropriate time to do this during the main walk of the file (see the comment at the top of
|
||||
// checkFunctionExpressionBodies). So it must be done now.
|
||||
getReturnTypeOfSignature(getSignatureFromDeclaration(node));
|
||||
}
|
||||
|
||||
if (node.body.kind === SyntaxKind.Block) {
|
||||
checkSourceElement(node.body);
|
||||
}
|
||||
|
||||
@@ -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'.
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
tests/cases/compiler/typeCheckObjectLiteralMethodBody.ts(1,13): error TS7010: 'bar', which lacks return-type annotation, implicitly has an 'any' return type.
|
||||
|
||||
|
||||
==== tests/cases/compiler/typeCheckObjectLiteralMethodBody.ts (1 errors) ====
|
||||
var foo = { bar() { return undefined } };
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS7010: 'bar', which lacks return-type annotation, implicitly has an 'any' return type.
|
||||
@@ -0,0 +1,5 @@
|
||||
//// [typeCheckObjectLiteralMethodBody.ts]
|
||||
var foo = { bar() { return undefined } };
|
||||
|
||||
//// [typeCheckObjectLiteralMethodBody.js]
|
||||
var foo = { bar: function () { return undefined; } };
|
||||
@@ -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.
|
||||
5
tests/baselines/reference/typeCheckReturnExpression.js
Normal file
5
tests/baselines/reference/typeCheckReturnExpression.js
Normal file
@@ -0,0 +1,5 @@
|
||||
//// [typeCheckReturnExpression.ts]
|
||||
var foo = () => undefined;
|
||||
|
||||
//// [typeCheckReturnExpression.js]
|
||||
var foo = function () { return undefined; };
|
||||
2
tests/cases/compiler/typeCheckObjectLiteralMethodBody.ts
Normal file
2
tests/cases/compiler/typeCheckObjectLiteralMethodBody.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
//@noImplicitAny: true
|
||||
var foo = { bar() { return undefined } };
|
||||
2
tests/cases/compiler/typeCheckReturnExpression.ts
Normal file
2
tests/cases/compiler/typeCheckReturnExpression.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
//@noImplicitAny: true
|
||||
var foo = () => undefined;
|
||||
Reference in New Issue
Block a user