Excess property checks for discriminated unions

This uses the same code as #14006, which improves error messages for
discriminated unions.
This commit is contained in:
Nathan Shively-Sanders
2017-06-08 11:01:32 -07:00
parent b94c51360b
commit 595cb11f22

View File

@@ -8964,6 +8964,13 @@ namespace ts {
(isTypeSubsetOf(globalObjectType, target) || (!isComparingJsxAttributes && isEmptyObjectType(target)))) {
return false;
}
if (target.flags & TypeFlags.Union) {
const discriminantType = findMatchingDiscriminantType(source, target as UnionType);
if (discriminantType) {
// check excess properties against discriminant type only, not the entire union
return hasExcessProperties(source, discriminantType, reportErrors);
}
}
for (const prop of getPropertiesOfObjectType(source)) {
if (!isKnownProperty(target, prop.name, isComparingJsxAttributes)) {
if (reportErrors) {