From 665667153623d6375d6ab40268dc09153a89ddb9 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 13 Mar 2019 06:51:05 -0700 Subject: [PATCH] Proper contravariance in type parameter promotion --- src/compiler/checker.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 06063793096..7e62e76f02b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14511,10 +14511,9 @@ namespace ts { emptyObjectType; } - function inferTypes(inferences: InferenceInfo[], originalSource: Type, originalTarget: Type, priority: InferencePriority = 0) { + function inferTypes(inferences: InferenceInfo[], originalSource: Type, originalTarget: Type, priority: InferencePriority = 0, contravariant = false) { let symbolStack: Symbol[]; let visited: Map; - let contravariant = false; let bivariant = false; let propagationType: Type; let allowComplexConstraintInference = true; @@ -23474,7 +23473,7 @@ namespace ts { // contextual signature starting with an empty set of inference candidates. const inferences = map(context.inferences, info => createInferenceInfo(info.typeParameter)); applyToParameterTypes(instantiatedSignature, contextualSignature, (source, target) => { - inferTypes(inferences, source, target); + inferTypes(inferences, source, target, /*priority*/ 0, /*contravariant*/ true); }); if (some(inferences, hasInferenceCandidates)) { // We have inference candidates, indicating that one or more type parameters are referenced