Skip to content

Commit 46da667

Browse files
committed
Return expressions always need to be type checked
1 parent f83d54b commit 46da667

File tree

5 files changed

+22
-1
lines changed

5 files changed

+22
-1
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7454,6 +7454,10 @@ module ts {
74547454
}
74557455

74567456
if (node.body) {
7457+
if (!node.type) {
7458+
getReturnTypeOfSignature(getSignatureFromDeclaration(node));
7459+
}
7460+
74577461
if (node.body.kind === SyntaxKind.Block) {
74587462
checkSourceElement(node.body);
74597463
}

tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.errors.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts(1,1): error TS1108: A 'return' statement can only be used within a function body.
2+
tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts(1,18): error TS2304: Cannot find name 'role'.
23
tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts(2,18): error TS2304: Cannot find name 'Role'.
34
tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts(4,26): error TS2503: Cannot find namespace 'ng'.
45

56

6-
==== tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts (3 errors) ====
7+
==== tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts (4 errors) ====
78
return this.edit(role)
89
~~~~~~
910
!!! error TS1108: A 'return' statement can only be used within a function body.
11+
~~~~
12+
!!! error TS2304: Cannot find name 'role'.
1013
.then((role: Role) =>
1114
~~~~
1215
!!! error TS2304: Cannot find name 'Role'.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
tests/cases/compiler/typeCheckReturnExpression.ts(1,11): error TS7011: Function expression, which lacks return-type annotation, implicitly has an 'any' return type.
2+
3+
4+
==== tests/cases/compiler/typeCheckReturnExpression.ts (1 errors) ====
5+
var foo = () => undefined;
6+
~~~~~~~~~~~~~~~
7+
!!! error TS7011: Function expression, which lacks return-type annotation, implicitly has an 'any' return type.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//// [typeCheckReturnExpression.ts]
2+
var foo = () => undefined;
3+
4+
//// [typeCheckReturnExpression.js]
5+
var foo = function () { return undefined; };
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
//@noImplicitAny: true
2+
var foo = () => undefined;

0 commit comments

Comments
 (0)