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 {
92589258 return false;
92599259 }
92609260
9261- function removeSubtypes(types: Type[]): boolean {
9261+ function removeSubtypes(types: Type[], primitivesOnly: boolean ): boolean {
92629262 const len = types.length;
92639263 if (len === 0 || isSetOfLiteralsFromSameEnum(types)) {
92649264 return true;
@@ -9273,9 +9273,11 @@ namespace ts {
92739273 if (count === 10000) {
92749274 // After 10000 subtype checks we estimate the remaining amount of work by assuming the
92759275 // 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.
92779279 const estimatedCount = (count / (len - i)) * len;
9278- if (estimatedCount > 1000000) {
9280+ if (estimatedCount > (primitivesOnly ? 25000000 : 1000000) ) {
92799281 error(currentNode, Diagnostics.Expression_produces_a_union_type_that_is_too_complex_to_represent);
92809282 return false;
92819283 }
@@ -9338,7 +9340,7 @@ namespace ts {
93389340 }
93399341 break;
93409342 case UnionReduction.Subtype:
9341- if (!removeSubtypes(typeSet)) {
9343+ if (!removeSubtypes(typeSet, !(includes & TypeFlags.StructuredOrInstantiable) )) {
93429344 return errorType;
93439345 }
93449346 break;
You can’t perform that action at this time.
0 commit comments