Merge pull request #28429 from Microsoft/fixEmptyObjectIntersection

Fix empty object intersections
This commit is contained in:
Anders Hejlsberg
2018-11-10 00:44:57 -08:00
committed by GitHub
6 changed files with 457 additions and 22 deletions

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;