File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -9258,7 +9258,7 @@ namespace ts {
9258
9258
return false;
9259
9259
}
9260
9260
9261
- function removeSubtypes(types: Type[]): boolean {
9261
+ function removeSubtypes(types: Type[], primitivesOnly: boolean ): boolean {
9262
9262
const len = types.length;
9263
9263
if (len === 0 || isSetOfLiteralsFromSameEnum(types)) {
9264
9264
return true;
@@ -9273,9 +9273,11 @@ namespace ts {
9273
9273
if (count === 10000) {
9274
9274
// After 10000 subtype checks we estimate the remaining amount of work by assuming the
9275
9275
// same ratio of checks to removals. If the estimated number of remaining type checks is
9276
- // greater than 1000000 we deem the union type too complex to represent.
9276
+ // greater than an upper limit we deem the union type too complex to represent. The
9277
+ // upper limit is 25M for unions of primitives only, and 1M otherwise. This for example
9278
+ // caps union types at 5000 unique literal types and 1000 unique object types.
9277
9279
const estimatedCount = (count / (len - i)) * len;
9278
- if (estimatedCount > 1000000) {
9280
+ if (estimatedCount > (primitivesOnly ? 25000000 : 1000000) ) {
9279
9281
error(currentNode, Diagnostics.Expression_produces_a_union_type_that_is_too_complex_to_represent);
9280
9282
return false;
9281
9283
}
@@ -9338,7 +9340,7 @@ namespace ts {
9338
9340
}
9339
9341
break;
9340
9342
case UnionReduction.Subtype:
9341
- if (!removeSubtypes(typeSet)) {
9343
+ if (!removeSubtypes(typeSet, !(includes & TypeFlags.StructuredOrInstantiable) )) {
9342
9344
return errorType;
9343
9345
}
9344
9346
break;
You can’t perform that action at this time.
0 commit comments