Binding pattern contextual type checks spread type

The spread type can contain properties that have been built up during
the construction of the object literal.
This commit is contained in:
Nathan Shively-Sanders
2017-10-03 12:41:33 -07:00
parent b111493276
commit 7b0e74d91a

View File

@@ -13890,7 +13890,7 @@ namespace ts {
// type with those properties for which the binding pattern specifies a default value.
if (contextualTypeHasPattern) {
for (const prop of getPropertiesOfType(contextualType)) {
if (!propertiesTable.get(prop.escapedName)) {
if (!propertiesTable.get(prop.escapedName) && !(spread && getPropertyOfType(spread, prop.escapedName))) {
if (!(prop.flags & SymbolFlags.Optional)) {
error(prop.valueDeclaration || (<TransientSymbol>prop).bindingElement,
Diagnostics.Initializer_provides_no_value_for_this_binding_element_and_the_binding_element_has_no_default_value);