@@ -15865,19 +15865,16 @@ namespace ts {
15865
15865
function getContextualReturnType(functionDecl: SignatureDeclaration): Type | undefined {
15866
15866
// If the containing function has a return type annotation, is a constructor, or is a get accessor whose
15867
15867
// corresponding set accessor has a type annotation, return statements in the function are contextually typed
15868
- if (functionDecl.kind === SyntaxKind.Constructor ||
15869
- getEffectiveReturnTypeNode(functionDecl) ||
15870
- isGetAccessorWithAnnotatedSetAccessor(functionDecl)) {
15871
- return getReturnTypeOfSignature(getSignatureFromDeclaration(functionDecl));
15868
+ const returnType = getReturnTypeFromAnnotation(functionDecl);
15869
+ if (returnType) {
15870
+ return returnType;
15872
15871
}
15873
-
15874
15872
// Otherwise, if the containing function is contextually typed by a function type with exactly one call signature
15875
15873
// and that call signature is non-generic, return statements are contextually typed by the return type of the signature
15876
15874
const signature = getContextualSignatureForFunctionLikeDeclaration(<FunctionExpression>functionDecl);
15877
15875
if (signature && !isResolvingReturnTypeOfSignature(signature)) {
15878
15876
return getReturnTypeOfSignature(signature);
15879
15877
}
15880
-
15881
15878
return undefined;
15882
15879
}
15883
15880
@@ -21557,9 +21554,9 @@ namespace ts {
21557
21554
// There is no point in doing an assignability check if the function
21558
21555
// has no explicit return type because the return type is directly computed
21559
21556
// from the yield expressions.
21560
- const returnType = getEffectiveReturnTypeNode (func);
21557
+ const returnType = getReturnTypeFromAnnotation (func);
21561
21558
if (returnType) {
21562
- const signatureElementType = getIteratedTypeOfGenerator(getTypeFromTypeNode( returnType) , isAsync) || anyType;
21559
+ const signatureElementType = getIteratedTypeOfGenerator(returnType, isAsync) || anyType;
21563
21560
checkTypeAssignableToAndOptionallyElaborate(yieldedType, signatureElementType, node.expression || node, node.expression);
21564
21561
}
21565
21562
@@ -24923,11 +24920,6 @@ namespace ts {
24923
24920
// TODO: Check that target label is valid
24924
24921
}
24925
24922
24926
- function isGetAccessorWithAnnotatedSetAccessor(node: SignatureDeclaration) {
24927
- return node.kind === SyntaxKind.GetAccessor
24928
- && getEffectiveSetAccessorTypeAnnotationNode(getDeclarationOfKind<SetAccessorDeclaration>(node.symbol, SyntaxKind.SetAccessor)!) !== undefined;
24929
- }
24930
-
24931
24923
function isUnwrappedReturnTypeVoidOrAny(func: SignatureDeclaration, returnType: Type): boolean {
24932
24924
const unwrappedReturnType = (getFunctionFlags(func) & FunctionFlags.AsyncGenerator) === FunctionFlags.Async
24933
24925
? getPromisedTypeOfPromise(returnType) // Async function
0 commit comments