Skip to content

Commit 15eaba2

Browse files
committed
Covariant inferences (other than never) preferred over contravariant
1 parent 435a12e commit 15eaba2

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13638,10 +13638,11 @@ namespace ts {
1363813638
if (!inferredType) {
1363913639
const signature = context.signature;
1364013640
if (signature) {
13641-
if (inference.contraCandidates) {
13642-
// If we have contravariant inferences we find the best common subtype and treat
13643-
// that as a single covariant candidate.
13644-
inference.candidates = append(inference.candidates, getContravariantInference(inference));
13641+
if (inference.contraCandidates && (!inference.candidates || inference.candidates.length === 1 && inference.candidates[0].flags & TypeFlags.Never)) {
13642+
// If we have contravariant inferences, but no covariant inferences or a single
13643+
// covariant inference of 'never', we find the best common subtype and treat that
13644+
// as a single covariant candidate.
13645+
inference.candidates = [getContravariantInference(inference)];
1364513646
inference.contraCandidates = undefined;
1364613647
}
1364713648
if (inference.candidates) {

0 commit comments

Comments
 (0)