Instantiating a signature in the context of another should infer from return type predicates if they match up (#30242)

* Instantiating a signature in the context of another should infer from return type predicates if they match up

* Invert condition per PR feedback
This commit is contained in:
Wesley Wigham
2019-03-07 17:39:58 -08:00
committed by GitHub
parent 4c9ad08610
commit e982240500
5 changed files with 153 additions and 0 deletions

View File

@@ -20042,6 +20042,12 @@ namespace ts {
});
if (!contextualMapper) {
inferTypes(context.inferences, getReturnTypeOfSignature(contextualSignature), getReturnTypeOfSignature(signature), InferencePriority.ReturnType);
const signaturePredicate = getTypePredicateOfSignature(signature);
const contextualPredicate = getTypePredicateOfSignature(sourceSignature);
if (signaturePredicate && contextualPredicate && signaturePredicate.kind === contextualPredicate.kind &&
(signaturePredicate.kind === TypePredicateKind.This || signaturePredicate.parameterIndex === (contextualPredicate as IdentifierTypePredicate).parameterIndex)) {
inferTypes(context.inferences, contextualPredicate.type, signaturePredicate.type, InferencePriority.ReturnType);
}
}
return getSignatureInstantiation(signature, getInferredTypes(context), isInJSFile(contextualSignature.declaration));
}