From f661508bb6da32f157008f0414d796f0ddf0ff8d Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 22 Jan 2015 14:51:37 -0800 Subject: [PATCH] Add missing optional properties only when not inferentially typing --- src/compiler/checker.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a3ea14dcb09..7233c2e85d5 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5455,9 +5455,10 @@ module ts { } } - // If object literal is contextually typed, add missing optional properties from the contextual type - // such that the resulting type becomes a subtype in cases where only optional properties were omitted - if (contextualType) { + // If object literal is contextually (but not inferentially) typed, copy missing optional properties from + // the contextual type such that the resulting type becomes a subtype in cases where only optional properties + // were omitted. There is no need to create new property objects as nothing in them needs to change. + if (contextualType && !isInferentialContext(contextualMapper)) { forEach(getPropertiesOfObjectType(contextualType), p => { if (p.flags & SymbolFlags.Optional && !hasProperty(properties, p.name)) { properties[p.name] = p;