Skip to content

Commit ffab267

Browse files
committed
Fix excess property check with empty target object type
1 parent dce7fca commit ffab267

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/compiler/checker.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8328,8 +8328,11 @@ namespace ts {
83288328
!t.numberIndexInfo;
83298329
}
83308330

8331-
function isEmptyObjectType(type: Type) {
8332-
return type.flags & TypeFlags.Object && isEmptyResolvedType(resolveStructuredTypeMembers(<ObjectType>type));
8331+
function isEmptyObjectType(type: Type): boolean {
8332+
return type.flags & TypeFlags.Object ? isEmptyResolvedType(resolveStructuredTypeMembers(<ObjectType>type)) :
8333+
type.flags & TypeFlags.Union ? forEach((<UnionType>type).types, isEmptyObjectType) :
8334+
type.flags & TypeFlags.Intersection ? !forEach((<UnionType>type).types, t => !isEmptyObjectType(t)) :
8335+
false;
83338336
}
83348337

83358338
function isEnumTypeRelatedTo(source: EnumType, target: EnumType, errorReporter?: ErrorReporter) {
@@ -8645,14 +8648,8 @@ namespace ts {
86458648
function isKnownProperty(type: Type, name: string, isComparingJsxAttributes: boolean): boolean {
86468649
if (type.flags & TypeFlags.Object) {
86478650
const resolved = resolveStructuredTypeMembers(<ObjectType>type);
8648-
if ((relation === assignableRelation || relation === comparableRelation) &&
8649-
(type === globalObjectType || (!isComparingJsxAttributes && isEmptyObjectType(resolved)))) {
8650-
return true;
8651-
}
8652-
else if (resolved.stringIndexInfo || (resolved.numberIndexInfo && isNumericLiteralName(name))) {
8653-
return true;
8654-
}
8655-
else if (getPropertyOfType(type, name) || (isComparingJsxAttributes && !isUnhyphenatedJsxName(name))) {
8651+
if (resolved.stringIndexInfo || resolved.numberIndexInfo && isNumericLiteralName(name) ||
8652+
getPropertyOfType(type, name) || isComparingJsxAttributes && !isUnhyphenatedJsxName(name)) {
86568653
// For JSXAttributes, if the attribute has a hyphenated name, consider that the attribute to be known.
86578654
return true;
86588655
}
@@ -8670,6 +8667,10 @@ namespace ts {
86708667
function hasExcessProperties(source: FreshObjectLiteralType, target: Type, reportErrors: boolean): boolean {
86718668
if (maybeTypeOfKind(target, TypeFlags.Object) && !(getObjectFlags(target) & ObjectFlags.ObjectLiteralPatternWithComputedProperties)) {
86728669
const isComparingJsxAttributes = !!(source.flags & TypeFlags.JsxAttributes);
8670+
if ((relation === assignableRelation || relation === comparableRelation) &&
8671+
(target === globalObjectType || (!isComparingJsxAttributes && isEmptyObjectType(target)))) {
8672+
return false;
8673+
}
86738674
for (const prop of getPropertiesOfObjectType(source)) {
86748675
if (!isKnownProperty(target, prop.name, isComparingJsxAttributes)) {
86758676
if (reportErrors) {

0 commit comments

Comments
 (0)