Add missing optional properties only when not inferentially typing

This commit is contained in:
Anders Hejlsberg 2015-01-22 14:51:37 -08:00
parent 21e6784038
commit f661508bb6

View File

@ -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;