Skip to content

Commit dc34c5e

Browse files
committed
Use getReturnTypeFromAnnotation instead of ad hoc checks
1 parent c367b91 commit dc34c5e

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15865,19 +15865,16 @@ namespace ts {
1586515865
function getContextualReturnType(functionDecl: SignatureDeclaration): Type | undefined {
1586615866
// If the containing function has a return type annotation, is a constructor, or is a get accessor whose
1586715867
// 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;
1587215871
}
15873-
1587415872
// Otherwise, if the containing function is contextually typed by a function type with exactly one call signature
1587515873
// and that call signature is non-generic, return statements are contextually typed by the return type of the signature
1587615874
const signature = getContextualSignatureForFunctionLikeDeclaration(<FunctionExpression>functionDecl);
1587715875
if (signature && !isResolvingReturnTypeOfSignature(signature)) {
1587815876
return getReturnTypeOfSignature(signature);
1587915877
}
15880-
1588115878
return undefined;
1588215879
}
1588315880

@@ -21557,9 +21554,9 @@ namespace ts {
2155721554
// There is no point in doing an assignability check if the function
2155821555
// has no explicit return type because the return type is directly computed
2155921556
// from the yield expressions.
21560-
const returnType = getEffectiveReturnTypeNode(func);
21557+
const returnType = getReturnTypeFromAnnotation(func);
2156121558
if (returnType) {
21562-
const signatureElementType = getIteratedTypeOfGenerator(getTypeFromTypeNode(returnType), isAsync) || anyType;
21559+
const signatureElementType = getIteratedTypeOfGenerator(returnType, isAsync) || anyType;
2156321560
checkTypeAssignableToAndOptionallyElaborate(yieldedType, signatureElementType, node.expression || node, node.expression);
2156421561
}
2156521562

@@ -24923,11 +24920,6 @@ namespace ts {
2492324920
// TODO: Check that target label is valid
2492424921
}
2492524922

24926-
function isGetAccessorWithAnnotatedSetAccessor(node: SignatureDeclaration) {
24927-
return node.kind === SyntaxKind.GetAccessor
24928-
&& getEffectiveSetAccessorTypeAnnotationNode(getDeclarationOfKind<SetAccessorDeclaration>(node.symbol, SyntaxKind.SetAccessor)!) !== undefined;
24929-
}
24930-
2493124923
function isUnwrappedReturnTypeVoidOrAny(func: SignatureDeclaration, returnType: Type): boolean {
2493224924
const unwrappedReturnType = (getFunctionFlags(func) & FunctionFlags.AsyncGenerator) === FunctionFlags.Async
2493324925
? getPromisedTypeOfPromise(returnType) // Async function

0 commit comments

Comments
 (0)