From 595cb11f22d4bb3fe4bbf3e4d0366c6b5903c57a Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Thu, 8 Jun 2017 11:01:32 -0700 Subject: [PATCH] Excess property checks for discriminated unions This uses the same code as #14006, which improves error messages for discriminated unions. --- src/compiler/checker.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 266fbe573be..ddfebd84ad6 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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) {