@@ -19212,8 +19212,20 @@ namespace ts {
19212
19212
return regularNew;
19213
19213
}
19214
19214
19215
- function createWideningContext(parent: WideningContext | undefined, propertyName: __String | undefined, siblings: Type[] | undefined): WideningContext {
19216
- return { parent, propertyName, siblings, resolvedProperties: undefined };
19215
+ function createSiblingWideningContext(siblings: Type[]): WideningContext {
19216
+ return { siblings };
19217
+ }
19218
+
19219
+ function createPropertyWideningContext(parent: WideningContext, propertyName: __String): WideningContext {
19220
+ const cache = (parent.childContexts ??= new Map<__String, WideningContext>());
19221
+ const existing = cache.get(propertyName);
19222
+ if (existing) {
19223
+ return existing;
19224
+ }
19225
+
19226
+ const context: WideningContext = { parent, propertyName };
19227
+ cache.set(propertyName, context);
19228
+ return context;
19217
19229
}
19218
19230
19219
19231
function getSiblingsOfContext(context: WideningContext): Type[] {
@@ -19256,7 +19268,7 @@ namespace ts {
19256
19268
return prop;
19257
19269
}
19258
19270
const original = getTypeOfSymbol(prop);
19259
- const propContext = context && createWideningContext (context, prop.escapedName, /*siblings*/ undefined );
19271
+ const propContext = context && createPropertyWideningContext (context, prop.escapedName);
19260
19272
const widened = getWidenedTypeWithContext(original, propContext);
19261
19273
return widened === original ? prop : createSymbolWithType(prop, widened);
19262
19274
}
@@ -19310,7 +19322,7 @@ namespace ts {
19310
19322
result = getWidenedTypeOfObjectLiteral(type, context);
19311
19323
}
19312
19324
else if (type.flags & TypeFlags.Union) {
19313
- const unionContext = context || createWideningContext(/*parent*/ undefined, /*propertyName*/ undefined, (<UnionType>type).types);
19325
+ const unionContext = context || createSiblingWideningContext( (<UnionType>type).types);
19314
19326
const widenedTypes = sameMap((<UnionType>type).types, t => t.flags & TypeFlags.Nullable ? t : getWidenedTypeWithContext(t, unionContext));
19315
19327
// Widening an empty object literal transitions from a highly restrictive type to
19316
19328
// a highly inclusive one. For that reason we perform subtype reduction here if the
0 commit comments