Skip to content

Commit 64a1229

Browse files
committed
Make an exception for primitive union comparisons
1 parent 935e27a commit 64a1229

File tree

6 files changed

+573
-2
lines changed

6 files changed

+573
-2
lines changed

src/compiler/checker.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17016,8 +17016,16 @@ namespace ts {
1701617016

1701717017
function areUnionsOrIntersectionsTooLarge(source: Type, target: Type, reportErrors: boolean) {
1701817018
if ((source.flags & TypeFlags.UnionOrIntersection) && (target.flags & TypeFlags.UnionOrIntersection)) {
17019-
const sourceSize = (source as UnionOrIntersectionType).types.length;
17020-
const targetSize = (target as UnionOrIntersectionType).types.length;
17019+
const sourceUnionOrIntersection = source as UnionOrIntersectionType;
17020+
const targetUnionOrIntersection = target as UnionOrIntersectionType;
17021+
17022+
if (sourceUnionOrIntersection.objectFlags & targetUnionOrIntersection.objectFlags & ObjectFlags.PrimitiveUnion) {
17023+
// There's a fast path for comparing primitive unions
17024+
return false;
17025+
}
17026+
17027+
const sourceSize = sourceUnionOrIntersection.types.length;
17028+
const targetSize = targetUnionOrIntersection.types.length;
1702117029
if (sourceSize * targetSize > 1E7) {
1702217030
if (reportErrors) {
1702317031
tracing.instant(tracing.Phase.CheckTypes, "areUnionsOrIntersectionsTooLarge_DepthLimit", { sourceId: source.id, sourceSize, targetId: target.id, targetSize });

tests/baselines/reference/largePrimitiveUnionComparisons.errors.txt

Lines changed: 114 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)