@@ -8855,46 +8855,37 @@ namespace ts {
8855
8855
return false;
8856
8856
}
8857
8857
8858
- function addTypeToUnion(typeSet: Type[], includes: TypeFlags, type: Type, noReduction: boolean ) {
8858
+ function addTypeToUnion(typeSet: Type[], includes: TypeFlags, type: Type) {
8859
8859
const flags = type.flags;
8860
8860
if (flags & TypeFlags.Union) {
8861
- return addTypesToUnion(typeSet, includes, (<UnionType>type).types, noReduction );
8861
+ return addTypesToUnion(typeSet, includes, (<UnionType>type).types);
8862
8862
}
8863
8863
// We ignore 'never' types in unions. Likewise, we ignore intersections of unit types as they are
8864
8864
// another form of 'never' (in that they have an empty value domain). We could in theory turn
8865
8865
// intersections of unit types into 'never' upon construction, but deferring the reduction makes it
8866
8866
// easier to reason about their origin.
8867
8867
if (!(flags & TypeFlags.Never || flags & TypeFlags.Intersection && isEmptyIntersectionType(<IntersectionType>type))) {
8868
8868
includes |= flags & ~TypeFlags.ConstructionFlags;
8869
- if (noReduction) {
8870
- addTypeToTypeSet(typeSet, type);
8871
- }
8872
- else if (flags & TypeFlags.AnyOrUnknown) {
8873
- if (type === wildcardType) includes |= TypeFlags.Wildcard;
8874
- }
8875
- else if (!strictNullChecks && flags & TypeFlags.Nullable) {
8869
+ if (type === wildcardType) includes |= TypeFlags.Wildcard;
8870
+ if (!strictNullChecks && flags & TypeFlags.Nullable) {
8876
8871
if (!(flags & TypeFlags.ContainsWideningType)) includes |= TypeFlags.NonWideningType;
8877
8872
}
8878
8873
else {
8879
- addTypeToTypeSet(typeSet, type);
8874
+ const len = typeSet.length;
8875
+ const index = len && type.id > typeSet[len - 1].id ? ~len : binarySearch(typeSet, type, getTypeId, compareValues);
8876
+ if (index < 0) {
8877
+ typeSet.splice(~index, 0, type);
8878
+ }
8880
8879
}
8881
8880
}
8882
8881
return includes;
8883
8882
}
8884
8883
8885
- function addTypeToTypeSet(typeSet: Type[], type: Type) {
8886
- const len = typeSet.length;
8887
- const index = len && type.id > typeSet[len - 1].id ? ~len : binarySearch(typeSet, type, getTypeId, compareValues);
8888
- if (index < 0) {
8889
- typeSet.splice(~index, 0, type);
8890
- }
8891
- }
8892
-
8893
8884
// Add the given types to the given type set. Order is preserved, duplicates are removed,
8894
8885
// and nested types of the given kind are flattened into the set.
8895
- function addTypesToUnion(typeSet: Type[], includes: TypeFlags, types: ReadonlyArray<Type>, noReduction: boolean ): TypeFlags {
8886
+ function addTypesToUnion(typeSet: Type[], includes: TypeFlags, types: ReadonlyArray<Type>): TypeFlags {
8896
8887
for (const type of types) {
8897
- includes = addTypeToUnion(typeSet, includes, type, noReduction );
8888
+ includes = addTypeToUnion(typeSet, includes, type);
8898
8889
}
8899
8890
return includes;
8900
8891
}
@@ -8971,7 +8962,7 @@ namespace ts {
8971
8962
return types[0];
8972
8963
}
8973
8964
const typeSet: Type[] = [];
8974
- const includes = addTypesToUnion(typeSet, 0, types, unionReduction === UnionReduction.None );
8965
+ const includes = addTypesToUnion(typeSet, 0, types);
8975
8966
if (unionReduction !== UnionReduction.None) {
8976
8967
if (includes & TypeFlags.AnyOrUnknown) {
8977
8968
return includes & TypeFlags.Any ? includes & TypeFlags.Wildcard ? wildcardType : anyType : unknownType;
0 commit comments