@@ -6906,6 +6906,8 @@ namespace ts {
6906
6906
containsString?: boolean;
6907
6907
containsNumber?: boolean;
6908
6908
containsStringOrNumberLiteral?: boolean;
6909
+ containsObjectType?: boolean;
6910
+ containsEmptyObject?: boolean;
6909
6911
unionIndex?: number;
6910
6912
}
6911
6913
@@ -7101,7 +7103,13 @@ namespace ts {
7101
7103
else if (type.flags & TypeFlags.Any) {
7102
7104
typeSet.containsAny = true;
7103
7105
}
7106
+ else if (getObjectFlags(type) & ObjectFlags.Anonymous && isEmptyObjectType(type)) {
7107
+ typeSet.containsEmptyObject = true;
7108
+ }
7104
7109
else if (!(type.flags & TypeFlags.Never) && (strictNullChecks || !(type.flags & TypeFlags.Nullable)) && !contains(typeSet, type)) {
7110
+ if (type.flags & TypeFlags.Object) {
7111
+ typeSet.containsObjectType = true;
7112
+ }
7105
7113
if (type.flags & TypeFlags.Union && typeSet.unionIndex === undefined) {
7106
7114
typeSet.unionIndex = typeSet.length;
7107
7115
}
@@ -7139,6 +7147,9 @@ namespace ts {
7139
7147
if (typeSet.containsAny) {
7140
7148
return anyType;
7141
7149
}
7150
+ if (typeSet.containsEmptyObject && !typeSet.containsObjectType) {
7151
+ typeSet.push(emptyObjectType);
7152
+ }
7142
7153
if (typeSet.length === 1) {
7143
7154
return typeSet[0];
7144
7155
}
@@ -8309,6 +8320,18 @@ namespace ts {
8309
8320
}
8310
8321
}
8311
8322
8323
+ function isEmptyResolvedType(t: ResolvedType) {
8324
+ return t.properties.length === 0 &&
8325
+ t.callSignatures.length === 0 &&
8326
+ t.constructSignatures.length === 0 &&
8327
+ !t.stringIndexInfo &&
8328
+ !t.numberIndexInfo;
8329
+ }
8330
+
8331
+ function isEmptyObjectType(type: Type) {
8332
+ return type.flags & TypeFlags.Object && isEmptyResolvedType(resolveStructuredTypeMembers(<ObjectType>type));
8333
+ }
8334
+
8312
8335
function isEnumTypeRelatedTo(source: EnumType, target: EnumType, errorReporter?: ErrorReporter) {
8313
8336
if (source === target) {
8314
8337
return true;
@@ -8644,18 +8667,6 @@ namespace ts {
8644
8667
return false;
8645
8668
}
8646
8669
8647
- function isEmptyResolvedType(t: ResolvedType) {
8648
- return t.properties.length === 0 &&
8649
- t.callSignatures.length === 0 &&
8650
- t.constructSignatures.length === 0 &&
8651
- !t.stringIndexInfo &&
8652
- !t.numberIndexInfo;
8653
- }
8654
-
8655
- function isEmptyObjectType(type: Type) {
8656
- return type.flags & TypeFlags.Object && isEmptyResolvedType(resolveStructuredTypeMembers(<ObjectType>type));
8657
- }
8658
-
8659
8670
function hasExcessProperties(source: FreshObjectLiteralType, target: Type, reportErrors: boolean): boolean {
8660
8671
if (maybeTypeOfKind(target, TypeFlags.Object) && !(getObjectFlags(target) & ObjectFlags.ObjectLiteralPatternWithComputedProperties)) {
8661
8672
const isComparingJsxAttributes = !!(source.flags & TypeFlags.JsxAttributes);
0 commit comments