mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Include missing optional properties in contextually typed object literal
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user