Skip to content

Commit c538f1f

Browse files
committed
Classify mapped type inferences as secondary
1 parent a230cb7 commit c538f1f

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8706,12 +8706,15 @@ namespace ts {
87068706
if (constraintType.flags & TypeFlags.Index) {
87078707
// We're inferring from some source type S to a homomorphic mapped type { [P in keyof T]: X },
87088708
// where T is a type variable. Use inferTypeForHomomorphicMappedType to infer a suitable source
8709-
// type and then infer from that type to T.
8709+
// type and then make a secondary inference from that type to T. We make a secondary inference
8710+
// such that direct inferences to T get priority over inferences to Partial<T>, for example.
87108711
const index = indexOf(typeVariables, (<IndexType>constraintType).type);
87118712
if (index >= 0 && !typeInferences[index].isFixed) {
87128713
const inferredType = inferTypeForHomomorphicMappedType(source, <MappedType>target);
87138714
if (inferredType) {
8715+
inferiority++;
87148716
inferFromTypes(inferredType, typeVariables[index]);
8717+
inferiority--;
87158718
}
87168719
}
87178720
return;

0 commit comments

Comments
 (0)