mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-16 07:13:45 -05: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:
@@ -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