Instantiate contextual type for return type in getReturnTypeFromBody

This commit is contained in:
Anders Hejlsberg 2019-07-12 11:11:36 -10:00
parent 60a1b1dc1a
commit e0599fd19c

View file

@ -19051,7 +19051,7 @@ namespace ts {
// If the given contextual type contains instantiable types and if a mapper representing
// return type inferences is available, instantiate those types using that mapper.
function instantiateContextualType(contextualType: Type | undefined, node: Expression, contextFlags?: ContextFlags): Type | undefined {
function instantiateContextualType(contextualType: Type | undefined, node: Node, contextFlags?: ContextFlags): Type | undefined {
if (contextualType && maybeTypeOfKind(contextualType, TypeFlags.Instantiable)) {
const inferenceContext = getInferenceContext(node);
// If no inferences have been made, nothing is gained from instantiating as type parameters
@ -23363,7 +23363,7 @@ namespace ts {
nextType && isUnitType(nextType)) {
const contextualType = !contextualSignature ? undefined :
contextualSignature === getSignatureFromDeclaration(func) ? isGenerator ? undefined : returnType :
getReturnTypeOfSignature(contextualSignature);
instantiateContextualType(getReturnTypeOfSignature(contextualSignature), func);
if (isGenerator) {
yieldType = getWidenedLiteralLikeTypeForContextualIterationTypeIfNeeded(yieldType, contextualType, IterationTypeKind.Yield, isAsync);
returnType = getWidenedLiteralLikeTypeForContextualIterationTypeIfNeeded(returnType, contextualType, IterationTypeKind.Return, isAsync);