Fix JSX attribute checking when spreading unions

Previously, the code didn't account for the fact that spreading a union
creates a union. In fact, before Decemeber, spreading a union in JSX
didn't create a union.

Now the check for properties of the spread type uses
`getPropertiesOfType`, which works with unions, instead of accessing the
`properties` property directly.
This commit is contained in:
Nathan Shively-Sanders
2018-01-22 13:34:12 -08:00
parent 5dcb937a48
commit ae652404cd
5 changed files with 159 additions and 1 deletions

View File

@@ -15310,7 +15310,7 @@ namespace ts {
// If the targetAttributesType is an emptyObjectType, indicating that there is no property named 'props' on this instance type.
// but there exists a sourceAttributesType, we need to explicitly give an error as normal assignability check allow excess properties and will pass.
if (targetAttributesType === emptyObjectType && (isTypeAny(sourceAttributesType) || (<ResolvedType>sourceAttributesType).properties.length > 0)) {
if (targetAttributesType === emptyObjectType && (isTypeAny(sourceAttributesType) || getPropertiesOfType(<ResolvedType>sourceAttributesType).length > 0)) {
error(openingLikeElement, Diagnostics.JSX_element_class_does_not_support_attributes_because_it_does_not_have_a_0_property, unescapeLeadingUnderscores(getJsxElementPropertiesName()));
}
else {