mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 21:36:50 -05:00
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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user