Skip to content

Commit d6b6bb7

Browse files
committed
Don't infer between tuple types with different arity
1 parent 5daffbb commit d6b6bb7

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/compiler/checker.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11603,6 +11603,13 @@ namespace ts {
1160311603
return undefined;
1160411604
}
1160511605

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+
1160611613
function getTypeFromInference(inference: InferenceInfo) {
1160711614
return inference.candidates ? getUnionType(inference.candidates, UnionReduction.Subtype) :
1160811615
inference.contraCandidates ? getIntersectionType(inference.contraCandidates) :
@@ -11873,9 +11880,8 @@ namespace ts {
1187311880
return;
1187411881
}
1187511882
}
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)) {
1187911885
inferFromProperties(source, target);
1188011886
inferFromSignatures(source, target, SignatureKind.Call);
1188111887
inferFromSignatures(source, target, SignatureKind.Construct);

0 commit comments

Comments
 (0)