mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 12:51:30 -05:00
Merge pull request #15033 from Microsoft/emptyObjectIntersection
Remove empty object types from intersection types
This commit is contained in:
@@ -6906,6 +6906,8 @@ namespace ts {
|
||||
containsString?: boolean;
|
||||
containsNumber?: boolean;
|
||||
containsStringOrNumberLiteral?: boolean;
|
||||
containsObjectType?: boolean;
|
||||
containsEmptyObject?: boolean;
|
||||
unionIndex?: number;
|
||||
}
|
||||
|
||||
@@ -7101,7 +7103,13 @@ namespace ts {
|
||||
else if (type.flags & TypeFlags.Any) {
|
||||
typeSet.containsAny = true;
|
||||
}
|
||||
else if (getObjectFlags(type) & ObjectFlags.Anonymous && isEmptyObjectType(type)) {
|
||||
typeSet.containsEmptyObject = true;
|
||||
}
|
||||
else if (!(type.flags & TypeFlags.Never) && (strictNullChecks || !(type.flags & TypeFlags.Nullable)) && !contains(typeSet, type)) {
|
||||
if (type.flags & TypeFlags.Object) {
|
||||
typeSet.containsObjectType = true;
|
||||
}
|
||||
if (type.flags & TypeFlags.Union && typeSet.unionIndex === undefined) {
|
||||
typeSet.unionIndex = typeSet.length;
|
||||
}
|
||||
@@ -7139,6 +7147,9 @@ namespace ts {
|
||||
if (typeSet.containsAny) {
|
||||
return anyType;
|
||||
}
|
||||
if (typeSet.containsEmptyObject && !typeSet.containsObjectType) {
|
||||
typeSet.push(emptyObjectType);
|
||||
}
|
||||
if (typeSet.length === 1) {
|
||||
return typeSet[0];
|
||||
}
|
||||
@@ -8309,6 +8320,18 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function isEmptyResolvedType(t: ResolvedType) {
|
||||
return t.properties.length === 0 &&
|
||||
t.callSignatures.length === 0 &&
|
||||
t.constructSignatures.length === 0 &&
|
||||
!t.stringIndexInfo &&
|
||||
!t.numberIndexInfo;
|
||||
}
|
||||
|
||||
function isEmptyObjectType(type: Type) {
|
||||
return type.flags & TypeFlags.Object && isEmptyResolvedType(resolveStructuredTypeMembers(<ObjectType>type));
|
||||
}
|
||||
|
||||
function isEnumTypeRelatedTo(source: EnumType, target: EnumType, errorReporter?: ErrorReporter) {
|
||||
if (source === target) {
|
||||
return true;
|
||||
@@ -8644,18 +8667,6 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
function isEmptyResolvedType(t: ResolvedType) {
|
||||
return t.properties.length === 0 &&
|
||||
t.callSignatures.length === 0 &&
|
||||
t.constructSignatures.length === 0 &&
|
||||
!t.stringIndexInfo &&
|
||||
!t.numberIndexInfo;
|
||||
}
|
||||
|
||||
function isEmptyObjectType(type: Type) {
|
||||
return type.flags & TypeFlags.Object && isEmptyResolvedType(resolveStructuredTypeMembers(<ObjectType>type));
|
||||
}
|
||||
|
||||
function hasExcessProperties(source: FreshObjectLiteralType, target: Type, reportErrors: boolean): boolean {
|
||||
if (maybeTypeOfKind(target, TypeFlags.Object) && !(getObjectFlags(target) & ObjectFlags.ObjectLiteralPatternWithComputedProperties)) {
|
||||
const isComparingJsxAttributes = !!(source.flags & TypeFlags.JsxAttributes);
|
||||
|
||||
Reference in New Issue
Block a user