From f40f0db6766b06ce60832be7835b074897521192 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 9 Sep 2017 12:43:39 -0700 Subject: [PATCH] Preserve intersections on the source side in type inference --- src/compiler/checker.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index aa5fbd6421..411b085508 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10578,7 +10578,7 @@ namespace ts { priority = savePriority; } } - else if (source.flags & TypeFlags.UnionOrIntersection) { + else if (source.flags & TypeFlags.Union) { // Source is a union or intersection type, infer from each constituent type const sourceTypes = (source).types; for (const sourceType of sourceTypes) { @@ -10587,7 +10587,7 @@ namespace ts { } else { source = getApparentType(source); - if (source.flags & TypeFlags.Object) { + if (source.flags & (TypeFlags.Object | TypeFlags.Intersection)) { const key = source.id + "," + target.id; if (visited && visited.get(key)) { return; @@ -10667,7 +10667,7 @@ namespace ts { function inferFromProperties(source: Type, target: Type) { const properties = getPropertiesOfObjectType(target); for (const targetProp of properties) { - const sourceProp = getPropertyOfObjectType(source, targetProp.escapedName); + const sourceProp = getPropertyOfType(source, targetProp.escapedName); if (sourceProp) { inferFromTypes(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp)); }