Skip to content

Commit 1639a5a

Browse files
authored
Handle huge unions better in createUnionOrIntersectionProperty (#30411)
* Handle huge unions better in createUnionOrIntersectionProperty * Mimic first-in-wins behavior of pushIfUnique to retain order * !props -> props.length === 0 (why dont we warn on that ffs) * Avoid collection into an array if there are no properties
1 parent b86dea0 commit 1639a5a

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/compiler/checker.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7772,7 +7772,7 @@ namespace ts {
77727772
}
77737773

77747774
function createUnionOrIntersectionProperty(containingType: UnionOrIntersectionType, name: __String): Symbol | undefined {
7775-
let props: Symbol[] | undefined;
7775+
const propSet = createMap<Symbol>();
77767776
let indexTypes: Type[] | undefined;
77777777
const isUnion = containingType.flags & TypeFlags.Union;
77787778
const excludeModifiers = isUnion ? ModifierFlags.NonPublicAccessibilityModifier : 0;
@@ -7787,7 +7787,10 @@ namespace ts {
77877787
const modifiers = prop ? getDeclarationModifierFlagsFromSymbol(prop) : 0;
77887788
if (prop && !(modifiers & excludeModifiers)) {
77897789
commonFlags &= prop.flags;
7790-
props = appendIfUnique(props, prop);
7790+
const id = "" + getSymbolId(prop);
7791+
if (!propSet.has(id)) {
7792+
propSet.set(id, prop);
7793+
}
77917794
checkFlags |= (isReadonlySymbol(prop) ? CheckFlags.Readonly : 0) |
77927795
(!(modifiers & ModifierFlags.NonPublicAccessibilityModifier) ? CheckFlags.ContainsPublic : 0) |
77937796
(modifiers & ModifierFlags.Protected ? CheckFlags.ContainsProtected : 0) |
@@ -7809,9 +7812,10 @@ namespace ts {
78097812
}
78107813
}
78117814
}
7812-
if (!props) {
7815+
if (!propSet.size) {
78137816
return undefined;
78147817
}
7818+
const props = arrayFrom(propSet.values());
78157819
if (props.length === 1 && !(checkFlags & CheckFlags.Partial) && !indexTypes) {
78167820
return props[0];
78177821
}

0 commit comments

Comments
 (0)