Skip to content

Commit 55da2b9

Browse files
committed
Preserve actual empty object type intersection
1 parent 59a8c94 commit 55da2b9

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/compiler/checker.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9097,8 +9097,11 @@ namespace ts {
90979097
if (flags & TypeFlags.Intersection) {
90989098
return addTypesToIntersection(typeSet, includes, (<IntersectionType>type).types);
90999099
}
9100-
if (getObjectFlags(type) & ObjectFlags.Anonymous && isEmptyObjectType(type)) {
9101-
includes |= TypeFlags.EmptyObject;
9100+
if (isEmptyAnonymousObjectType(type)) {
9101+
if (!(includes & TypeFlags.EmptyObject)) {
9102+
includes |= TypeFlags.EmptyObject;
9103+
typeSet.push(type);
9104+
}
91029105
}
91039106
else {
91049107
includes |= flags & ~TypeFlags.ConstructionFlags;
@@ -9229,8 +9232,8 @@ namespace ts {
92299232
includes & TypeFlags.ESSymbol && includes & TypeFlags.UniqueESSymbol) {
92309233
removeRedundantPrimitiveTypes(typeSet, includes);
92319234
}
9232-
if (includes & TypeFlags.EmptyObject && !(includes & TypeFlags.Object)) {
9233-
typeSet.push(emptyObjectType);
9235+
if (includes & TypeFlags.EmptyObject && includes & TypeFlags.Object) {
9236+
orderedRemoveItemAt(typeSet, findIndex(typeSet, isEmptyAnonymousObjectType));
92349237
}
92359238
if (typeSet.length === 0) {
92369239
return unknownType;
@@ -11277,6 +11280,10 @@ namespace ts {
1127711280
false;
1127811281
}
1127911282

11283+
function isEmptyAnonymousObjectType(type: Type) {
11284+
return !!(getObjectFlags(type) & ObjectFlags.Anonymous) && isEmptyObjectType(type);
11285+
}
11286+
1128011287
function isEnumTypeRelatedTo(sourceSymbol: Symbol, targetSymbol: Symbol, errorReporter?: ErrorReporter) {
1128111288
if (sourceSymbol === targetSymbol) {
1128211289
return true;

0 commit comments

Comments
 (0)