@@ -9890,28 +9890,28 @@ namespace ts {
9890
9890
return links.resolvedType;
9891
9891
}
9892
9892
9893
- function addTypeToIntersection(typeSet: Type[] , includes: TypeFlags, type: Type) {
9893
+ function addTypeToIntersection(typeSet: Map< Type> , includes: TypeFlags, type: Type) {
9894
9894
const flags = type.flags;
9895
9895
if (flags & TypeFlags.Intersection) {
9896
9896
return addTypesToIntersection(typeSet, includes, (<IntersectionType>type).types);
9897
9897
}
9898
9898
if (isEmptyAnonymousObjectType(type)) {
9899
9899
if (!(includes & TypeFlags.IncludesEmptyObject)) {
9900
9900
includes |= TypeFlags.IncludesEmptyObject;
9901
- typeSet.push( type);
9901
+ typeSet.set(type.id.toString(), type);
9902
9902
}
9903
9903
}
9904
9904
else {
9905
9905
if (flags & TypeFlags.AnyOrUnknown) {
9906
9906
if (type === wildcardType) includes |= TypeFlags.IncludesWildcard;
9907
9907
}
9908
- else if ((strictNullChecks || !(flags & TypeFlags.Nullable)) && !contains( typeSet, type)) {
9908
+ else if ((strictNullChecks || !(flags & TypeFlags.Nullable)) && !typeSet.has( type.id.toString() )) {
9909
9909
if (type.flags & TypeFlags.Unit && includes & TypeFlags.Unit) {
9910
9910
// We have seen two distinct unit types which means we should reduce to an
9911
9911
// empty intersection. Adding TypeFlags.NonPrimitive causes that to happen.
9912
9912
includes |= TypeFlags.NonPrimitive;
9913
9913
}
9914
- typeSet.push( type);
9914
+ typeSet.set(type.id.toString(), type);
9915
9915
}
9916
9916
includes |= flags & TypeFlags.IncludesMask;
9917
9917
}
@@ -9920,7 +9920,7 @@ namespace ts {
9920
9920
9921
9921
// Add the given types to the given type set. Order is preserved, freshness is removed from literal
9922
9922
// types, duplicates are removed, and nested types of the given kind are flattened into the set.
9923
- function addTypesToIntersection(typeSet: Type[] , includes: TypeFlags, types: ReadonlyArray<Type>) {
9923
+ function addTypesToIntersection(typeSet: Map< Type> , includes: TypeFlags, types: ReadonlyArray<Type>) {
9924
9924
for (const type of types) {
9925
9925
includes = addTypeToIntersection(typeSet, includes, getRegularTypeOfLiteralType(type));
9926
9926
}
@@ -10027,8 +10027,9 @@ namespace ts {
10027
10027
// Also, unlike union types, the order of the constituent types is preserved in order that overload resolution
10028
10028
// for intersections of types with signatures can be deterministic.
10029
10029
function getIntersectionType(types: ReadonlyArray<Type>, aliasSymbol?: Symbol, aliasTypeArguments?: ReadonlyArray<Type>): Type {
10030
- const typeSet: Type[] = [];
10031
- const includes = addTypesToIntersection(typeSet, 0, types);
10030
+ const typeMembershipMap: Map<Type> = createMap();
10031
+ const includes = addTypesToIntersection(typeMembershipMap, 0, types);
10032
+ const typeSet: Type[] = arrayFrom(typeMembershipMap.values());
10032
10033
// An intersection type is considered empty if it contains
10033
10034
// the type never, or
10034
10035
// more than one unit type or,
0 commit comments