Skip to content

Commit 68ef6c9

Browse files
committed
Improve logic for choosing between co- and contra-variant inferences
1 parent dfb4054 commit 68ef6c9

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22329,12 +22329,11 @@ namespace ts {
2232922329
if (signature) {
2233022330
const inferredCovariantType = inference.candidates ? getCovariantInference(inference, signature) : undefined;
2233122331
if (inference.contraCandidates) {
22332-
const inferredContravariantType = getContravariantInference(inference);
2233322332
// If we have both co- and contra-variant inferences, we prefer the contra-variant inference
22334-
// unless the co-variant inference is a subtype and not 'never'.
22333+
// unless the co-variant inference is a subtype of some contra-variant inference and not 'never'.
2233522334
inferredType = inferredCovariantType && !(inferredCovariantType.flags & TypeFlags.Never) &&
22336-
isTypeSubtypeOf(inferredCovariantType, inferredContravariantType) ?
22337-
inferredCovariantType : inferredContravariantType;
22335+
some(inference.contraCandidates, t => isTypeSubtypeOf(inferredCovariantType, t)) ?
22336+
inferredCovariantType : getContravariantInference(inference);
2233822337
}
2233922338
else if (inferredCovariantType) {
2234022339
inferredType = inferredCovariantType;

0 commit comments

Comments
 (0)