Include missing optional properties in contextually typed object literal

This commit is contained in:
Anders Hejlsberg
2015-01-22 11:03:15 -08:00
parent 2052ac3958
commit 883385f5cb
+10
View File
@@ -5455,6 +5455,16 @@ 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) {
forEach(getPropertiesOfObjectType(contextualType), p => {
if (p.flags & SymbolFlags.Optional && !hasProperty(properties, p.name)) {
properties[p.name] = p;
}
});
}
var stringIndexType = getIndexType(IndexKind.String);
var numberIndexType = getIndexType(IndexKind.Number);
var result = createAnonymousType(node.symbol, properties, emptyArray, emptyArray, stringIndexType, numberIndexType);