From c538f1fdf7311e63775d10e44b2e7011e30e462e Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 3 Dec 2016 11:03:18 -0800 Subject: [PATCH] Classify mapped type inferences as secondary --- src/compiler/checker.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 81f982e4dc0..adeb7a76376 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8706,12 +8706,15 @@ namespace ts { if (constraintType.flags & TypeFlags.Index) { // We're inferring from some source type S to a homomorphic mapped type { [P in keyof T]: X }, // where T is a type variable. Use inferTypeForHomomorphicMappedType to infer a suitable source - // type and then infer from that type to T. + // type and then make a secondary inference from that type to T. We make a secondary inference + // such that direct inferences to T get priority over inferences to Partial, for example. const index = indexOf(typeVariables, (constraintType).type); if (index >= 0 && !typeInferences[index].isFixed) { const inferredType = inferTypeForHomomorphicMappedType(source, target); if (inferredType) { + inferiority++; inferFromTypes(inferredType, typeVariables[index]); + inferiority--; } } return;