mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-10 18:04:18 -05:00
Error on the return statement itself when checking against function return types.
This commit is contained in:
@@ -17922,27 +17922,27 @@ namespace ts {
|
||||
|
||||
if (func.kind === SyntaxKind.SetAccessor) {
|
||||
if (node.expression) {
|
||||
error(node.expression, Diagnostics.Setters_cannot_return_a_value);
|
||||
error(node, Diagnostics.Setters_cannot_return_a_value);
|
||||
}
|
||||
}
|
||||
else if (func.kind === SyntaxKind.Constructor) {
|
||||
if (node.expression && !checkTypeAssignableTo(exprType, returnType, node.expression)) {
|
||||
error(node.expression, Diagnostics.Return_type_of_constructor_signature_must_be_assignable_to_the_instance_type_of_the_class);
|
||||
if (node.expression && !checkTypeAssignableTo(exprType, returnType, node)) {
|
||||
error(node, Diagnostics.Return_type_of_constructor_signature_must_be_assignable_to_the_instance_type_of_the_class);
|
||||
}
|
||||
}
|
||||
else if (func.type || isGetAccessorWithAnnotatedSetAccessor(func)) {
|
||||
if (isAsyncFunctionLike(func)) {
|
||||
const promisedType = getPromisedType(returnType);
|
||||
const awaitedType = checkAwaitedType(exprType, node.expression || node, Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member);
|
||||
const awaitedType = checkAwaitedType(exprType, node, Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member);
|
||||
if (promisedType) {
|
||||
// If the function has a return type, but promisedType is
|
||||
// undefined, an error will be reported in checkAsyncFunctionReturnType
|
||||
// so we don't need to report one here.
|
||||
checkTypeAssignableTo(awaitedType, promisedType, node.expression || node);
|
||||
checkTypeAssignableTo(awaitedType, promisedType, node);
|
||||
}
|
||||
}
|
||||
else {
|
||||
checkTypeAssignableTo(exprType, returnType, node.expression || node);
|
||||
checkTypeAssignableTo(exprType, returnType, node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user