Skip to content

Commit 2d65c9b

Browse files
committed
Improve perf of unions with many primitives
1 parent d1d65cb commit 2d65c9b

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/compiler/checker.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -22168,8 +22168,9 @@ namespace ts {
2216822168
// constituent types keyed by the literal types of the property by that name in each constituent type.
2216922169
function getKeyPropertyName(unionType: UnionType): __String | undefined {
2217022170
const types = unionType.types;
22171-
// We only construct maps for large unions with non-primitive constituents.
22172-
if (types.length < 10 || getObjectFlags(unionType) & ObjectFlags.PrimitiveUnion) {
22171+
// We only construct maps for unions with many non-primitive constituents.
22172+
if (types.length < 10 || getObjectFlags(unionType) & ObjectFlags.PrimitiveUnion ||
22173+
countWhere(types, t => !!(t.flags & (TypeFlags.Object | TypeFlags.InstantiableNonPrimitive))) < 10) {
2217322174
return undefined;
2217422175
}
2217522176
if (unionType.keyPropertyName === undefined) {

0 commit comments

Comments
 (0)