mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-11-18 20:11:14 +00:00
in noImplicitReturns mode, also disallow "return;"
In --noImplicitReturns mode, if a function specifies a return type, disallow empty "return;" statements. Fixes #5916.
This commit is contained in:
1 parent
0f6dbd0250
commit
5132ea64ea
4 files changed
+116
-5
No files matched your search
@@ -13842,11 +13842,11 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
if (node.expression) {
|
||||
const func = getContainingFunction(node);
|
||||
if (func) {
|
||||
const signature = getSignatureFromDeclaration(func);
|
||||
const returnType = getReturnTypeOfSignature(signature);
|
||||
const func = getContainingFunction(node);
|
||||
if (func) {
|
||||
const signature = getSignatureFromDeclaration(func);
|
||||
const returnType = getReturnTypeOfSignature(signature);
|
||||
if (node.expression) {
|
||||
const exprType = checkExpressionCached(node.expression);
|
||||
|
||||
if (func.asteriskToken) {
|
||||
@@ -13881,6 +13881,10 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (compilerOptions.noImplicitReturns && !maybeTypeOfKind(returnType, TypeFlags.Void | TypeFlags.Any)) {
|
||||
// The function has a return type, but the return statement doesn't have an expression.
|
||||
error(node, Diagnostics.Not_all_code_paths_return_a_value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user