@@ -11603,6 +11603,13 @@ namespace ts {
11603
11603
return undefined;
11604
11604
}
11605
11605
11606
+ function typesDefinitelyUnrelated(source: Type, target: Type) {
11607
+ // Two tuple types with different arity are definitely unrelated.
11608
+ // Two object types that each have a property that is unmatched in the other are definitely unrelated.
11609
+ return isTupleType(source) && isTupleType(target) && getTypeReferenceArity(<TypeReference>source) !== getTypeReferenceArity(<TypeReference>target) ||
11610
+ !!getUnmatchedProperty(source, target, /*requireOptionalProperties*/ false) && !!getUnmatchedProperty(target, source, /*requireOptionalProperties*/ false);
11611
+ }
11612
+
11606
11613
function getTypeFromInference(inference: InferenceInfo) {
11607
11614
return inference.candidates ? getUnionType(inference.candidates, UnionReduction.Subtype) :
11608
11615
inference.contraCandidates ? getIntersectionType(inference.contraCandidates) :
@@ -11873,9 +11880,8 @@ namespace ts {
11873
11880
return;
11874
11881
}
11875
11882
}
11876
- // Infer from the members of source and target only if the two types are possibly related. We check
11877
- // in both directions because we may be inferring for a co-variant or a contra-variant position.
11878
- if (!getUnmatchedProperty(source, target, /*requireOptionalProperties*/ false) || !getUnmatchedProperty(target, source, /*requireOptionalProperties*/ false)) {
11883
+ // Infer from the members of source and target only if the two types are possibly related
11884
+ if (!typesDefinitelyUnrelated(source, target)) {
11879
11885
inferFromProperties(source, target);
11880
11886
inferFromSignatures(source, target, SignatureKind.Call);
11881
11887
inferFromSignatures(source, target, SignatureKind.Construct);
0 commit comments