mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 02:33:53 -06:00
Return expressions always need to be type checked
This commit is contained in:
parent
f83d54b18f
commit
46da6678ad
@ -7454,6 +7454,10 @@ module ts {
|
||||
}
|
||||
|
||||
if (node.body) {
|
||||
if (!node.type) {
|
||||
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/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/typeCheckReturnExpression.ts
Normal file
2
tests/cases/compiler/typeCheckReturnExpression.ts
Normal file
@ -0,0 +1,2 @@
|
||||
//@noImplicitAny: true
|
||||
var foo = () => undefined;
|
||||
Loading…
x
Reference in New Issue
Block a user