Preserve actual empty object type intersection

This commit is contained in:
Anders Hejlsberg 2018-11-08 17:59:03 +01:00
parent 59a8c94ff1
commit 55da2b9669

View File

@ -9097,8 +9097,11 @@ namespace ts {
if (flags & TypeFlags.Intersection) {
return addTypesToIntersection(typeSet, includes, (<IntersectionType>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;