Skip to content

Commit 595cb11

Browse files
committed
Excess property checks for discriminated unions
This uses the same code as #14006, which improves error messages for discriminated unions.
1 parent b94c513 commit 595cb11

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/compiler/checker.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8964,6 +8964,13 @@ namespace ts {
89648964
(isTypeSubsetOf(globalObjectType, target) || (!isComparingJsxAttributes && isEmptyObjectType(target)))) {
89658965
return false;
89668966
}
8967+
if (target.flags & TypeFlags.Union) {
8968+
const discriminantType = findMatchingDiscriminantType(source, target as UnionType);
8969+
if (discriminantType) {
8970+
// check excess properties against discriminant type only, not the entire union
8971+
return hasExcessProperties(source, discriminantType, reportErrors);
8972+
}
8973+
}
89678974
for (const prop of getPropertiesOfObjectType(source)) {
89688975
if (!isKnownProperty(target, prop.name, isComparingJsxAttributes)) {
89698976
if (reportErrors) {

0 commit comments

Comments
 (0)