diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 23ccfe95c48..48ca8fbff08 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9097,8 +9097,11 @@ namespace ts { if (flags & TypeFlags.Intersection) { return addTypesToIntersection(typeSet, includes, (type).types); } - if (getObjectFlags(type) & ObjectFlags.Anonymous && isEmptyObjectType(type)) { - includes |= TypeFlags.EmptyObject; + if (isEmptyAnonymousObjectType(type)) { + if (!(includes & TypeFlags.EmptyObject)) { + includes |= TypeFlags.EmptyObject; + typeSet.push(type); + } } else { includes |= flags & ~TypeFlags.ConstructionFlags; @@ -9229,8 +9232,8 @@ namespace ts { includes & TypeFlags.ESSymbol && includes & TypeFlags.UniqueESSymbol) { removeRedundantPrimitiveTypes(typeSet, includes); } - if (includes & TypeFlags.EmptyObject && !(includes & TypeFlags.Object)) { - typeSet.push(emptyObjectType); + if (includes & TypeFlags.EmptyObject && includes & TypeFlags.Object) { + orderedRemoveItemAt(typeSet, findIndex(typeSet, isEmptyAnonymousObjectType)); } if (typeSet.length === 0) { return unknownType; @@ -11277,6 +11280,10 @@ namespace ts { false; } + function isEmptyAnonymousObjectType(type: Type) { + return !!(getObjectFlags(type) & ObjectFlags.Anonymous) && isEmptyObjectType(type); + } + function isEnumTypeRelatedTo(sourceSymbol: Symbol, targetSymbol: Symbol, errorReporter?: ErrorReporter) { if (sourceSymbol === targetSymbol) { return true;