@typescript-deploys/pr-build 5.0.0-pr-52947-27 → 5.0.0-pr-52944-25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/tsc.js CHANGED
@@ -3783,7 +3783,6 @@ var TypeFlags = /* @__PURE__ */ ((TypeFlags2) => {
3783
3783
  TypeFlags2[TypeFlags2["IncludesEmptyObject"] = 16777216 /* Conditional */] = "IncludesEmptyObject";
3784
3784
  TypeFlags2[TypeFlags2["IncludesInstantiable"] = 33554432 /* Substitution */] = "IncludesInstantiable";
3785
3785
  TypeFlags2[TypeFlags2["NotPrimitiveUnion"] = 36323363] = "NotPrimitiveUnion";
3786
- TypeFlags2[TypeFlags2["HasWrapper"] = 402668540] = "HasWrapper";
3787
3786
  return TypeFlags2;
3788
3787
  })(TypeFlags || {});
3789
3788
  var ObjectFlags = /* @__PURE__ */ ((ObjectFlags3) => {
@@ -54422,27 +54421,15 @@ function createTypeChecker(host) {
54422
54421
  isInJSFile(signature.declaration)
54423
54422
  );
54424
54423
  }
54425
- function getBaseSignature(signature) {
54426
- const typeParameters = signature.typeParameters;
54427
- if (typeParameters) {
54428
- if (signature.baseSignatureCache) {
54429
- return signature.baseSignatureCache;
54430
- }
54431
- const typeEraser = createTypeEraser(typeParameters);
54432
- const baseConstraintMapper = createTypeMapper(typeParameters, map(typeParameters, (tp) => getConstraintOfTypeParameter(tp) || unknownType));
54433
- let baseConstraints = map(typeParameters, (tp) => instantiateType(tp, baseConstraintMapper) || unknownType);
54434
- for (let i = 0; i < typeParameters.length - 1; i++) {
54435
- baseConstraints = instantiateTypes(baseConstraints, baseConstraintMapper);
54436
- }
54437
- baseConstraints = instantiateTypes(baseConstraints, typeEraser);
54438
- return signature.baseSignatureCache = instantiateSignature(
54439
- signature,
54440
- createTypeMapper(typeParameters, baseConstraints),
54441
- /*eraseTypeParameters*/
54442
- true
54443
- );
54424
+ function getTypeParameterConstraintMapper(typeParameters) {
54425
+ const typeEraser = createTypeEraser(typeParameters);
54426
+ const baseConstraintMapper = createTypeMapper(typeParameters, map(typeParameters, (tp) => getConstraintOfTypeParameter(tp) || unknownType));
54427
+ let baseConstraints = map(typeParameters, (tp) => instantiateType(tp, baseConstraintMapper) || unknownType);
54428
+ for (let i = 0; i < typeParameters.length - 1; i++) {
54429
+ baseConstraints = instantiateTypes(baseConstraints, baseConstraintMapper);
54444
54430
  }
54445
- return signature;
54431
+ baseConstraints = instantiateTypes(baseConstraints, typeEraser);
54432
+ return createTypeMapper(typeParameters, baseConstraints);
54446
54433
  }
54447
54434
  function getOrCreateTypeFromSignature(signature) {
54448
54435
  var _a2;
@@ -56967,9 +56954,9 @@ function createTypeChecker(host) {
56967
56954
  }
56968
56955
  }
56969
56956
  if (!checkTypeDeferred) {
56970
- inferTypes(context.inferences, checkType, instantiateType(extendsType, freshMapper), 512 /* NoConstraints */ | 1024 /* AlwaysStrict */);
56957
+ inferTypes(context, checkType, instantiateType(extendsType, freshMapper), 512 /* NoConstraints */ | 1024 /* AlwaysStrict */);
56971
56958
  }
56972
- const innerMapper = combineTypeMappers(freshMapper, context.mapper);
56959
+ const innerMapper = combineTypeMappers(freshMapper, getMapperFromContext(context));
56973
56960
  combinedMapper = mapper ? combineTypeMappers(innerMapper, mapper) : innerMapper;
56974
56961
  }
56975
56962
  const inferredExtendsType = combinedMapper ? instantiateType(root.extendsType, combinedMapper) : extendsType;
@@ -57656,8 +57643,11 @@ function createTypeChecker(host) {
57656
57643
  void 0
57657
57644
  );
57658
57645
  }
57659
- function createBackreferenceMapper(context, index) {
57660
- const forwardInferences = context.inferences.slice(index);
57646
+ function createBackreferenceMapper(context, inference) {
57647
+ const inferences = context.inferences.indexOf(inference) >= 0 ? context.inferences : context.freeTypeVariables;
57648
+ Debug.assert(inferences, "Inference for backreference mapper must exist within provided context");
57649
+ const index = inferences.indexOf(inference);
57650
+ const forwardInferences = inferences.slice(index);
57661
57651
  return createTypeMapper(map(forwardInferences, (i) => i.typeParameter), map(forwardInferences, () => unknownType));
57662
57652
  }
57663
57653
  function combineTypeMappers(mapper1, mapper2) {
@@ -59307,7 +59297,7 @@ function createTypeChecker(host) {
59307
59297
  function tryElaborateErrorsForPrimitivesAndObjects(source2, target2) {
59308
59298
  const sourceType = symbolValueDeclarationIsContextSensitive(source2.symbol) ? typeToString(source2, source2.symbol.valueDeclaration) : typeToString(source2);
59309
59299
  const targetType = symbolValueDeclarationIsContextSensitive(target2.symbol) ? typeToString(target2, target2.symbol.valueDeclaration) : typeToString(target2);
59310
- if (globalStringType === source2 && stringType === target2 || globalNumberType === source2 && numberType === target2 || globalBooleanType === source2 && booleanType === target2 || getGlobalESSymbolType() === source2 && esSymbolType === target2 || getGlobalBigIntType() === source2 && bigintType === target2) {
59300
+ if (globalStringType === source2 && stringType === target2 || globalNumberType === source2 && numberType === target2 || globalBooleanType === source2 && booleanType === target2 || getGlobalESSymbolType() === source2 && esSymbolType === target2) {
59311
59301
  reportError(Diagnostics._0_is_a_primitive_but_1_is_a_wrapper_object_Prefer_using_0_when_possible, targetType, sourceType);
59312
59302
  }
59313
59303
  }
@@ -59464,9 +59454,6 @@ function createTypeChecker(host) {
59464
59454
  }
59465
59455
  if (source2.flags & 524288 /* Object */ && target2.flags & 134348796 /* Primitive */) {
59466
59456
  tryElaborateErrorsForPrimitivesAndObjects(source2, target2);
59467
- }
59468
- if (target2.flags & 524288 /* Object */ && source2.flags & 134348796 /* Primitive */) {
59469
- tryElaborateErrorsForPrimitivesAndObjects(target2, source2);
59470
59457
  } else if (source2.symbol && source2.flags & 524288 /* Object */ && globalObjectType === source2) {
59471
59458
  reportError(Diagnostics.The_Object_type_is_assignable_to_very_few_other_types_Did_you_mean_to_use_the_any_type_instead);
59472
59459
  } else if (getObjectFlags(source2) & 2048 /* JsxAttributes */ && target2.flags & 2097152 /* Intersection */) {
@@ -60474,9 +60461,10 @@ function createTypeChecker(host) {
60474
60461
  0 /* None */,
60475
60462
  isRelatedToWorker
60476
60463
  );
60477
- inferTypes(ctx.inferences, target2.extendsType, sourceExtends, 512 /* NoConstraints */ | 1024 /* AlwaysStrict */);
60478
- sourceExtends = instantiateType(sourceExtends, ctx.mapper);
60479
- mapper = ctx.mapper;
60464
+ inferTypes(ctx, target2.extendsType, sourceExtends, 512 /* NoConstraints */ | 1024 /* AlwaysStrict */);
60465
+ const newMapper = getMapperFromContext(ctx);
60466
+ sourceExtends = instantiateType(sourceExtends, newMapper);
60467
+ mapper = newMapper;
60480
60468
  }
60481
60469
  if (isTypeIdenticalTo(sourceExtends, target2.extendsType) && (isRelatedTo(source2.checkType, target2.checkType, 3 /* Both */) || isRelatedTo(target2.checkType, source2.checkType, 3 /* Both */))) {
60482
60470
  if (result2 = isRelatedTo(instantiateType(getTrueTypeFromConditionalType(source2), mapper), getTrueTypeFromConditionalType(target2), 3 /* Both */, reportErrors2)) {
@@ -60514,13 +60502,8 @@ function createTypeChecker(host) {
60514
60502
  }
60515
60503
  const sourceIsPrimitive = !!(sourceFlags & 134348796 /* Primitive */);
60516
60504
  if (relation !== identityRelation) {
60517
- const originalSource = source2;
60518
- const originalFlags = sourceFlags;
60519
60505
  source2 = getApparentType(source2);
60520
60506
  sourceFlags = source2.flags;
60521
- if (source2 !== originalSource && originalFlags & 402668540 /* HasWrapper */ && !(sourceFlags & 402668540 /* HasWrapper */) && source2 === target2) {
60522
- return 0 /* False */;
60523
- }
60524
60507
  } else if (isGenericMappedType(source2)) {
60525
60508
  return 0 /* False */;
60526
60509
  }
@@ -62319,7 +62302,12 @@ function createTypeChecker(host) {
62319
62302
  return createInferenceContextWorker(typeParameters.map(createInferenceInfo), signature, flags, compareTypes || compareTypesAssignable);
62320
62303
  }
62321
62304
  function cloneInferenceContext(context, extraFlags = 0) {
62322
- return context && createInferenceContextWorker(map(context.inferences, cloneInferenceInfo), context.signature, context.flags | extraFlags, context.compareTypes);
62305
+ const newContext = context && createInferenceContextWorker(map(context.inferences, cloneInferenceInfo), context.signature, context.flags | extraFlags, context.compareTypes);
62306
+ if (context && context.freeTypeVariables) {
62307
+ newContext.freeTypeVariables = map(context.freeTypeVariables, cloneInferenceInfo);
62308
+ newContext.freeTypeVariableSourceSignatures = new Map(mapIterator(context.freeTypeVariableSourceSignatures.entries(), ([k, v]) => [k, new Map(v.entries())]));
62309
+ }
62310
+ return newContext;
62323
62311
  }
62324
62312
  function createInferenceContextWorker(inferences, signature, flags, compareTypes) {
62325
62313
  const context = {
@@ -62336,20 +62324,29 @@ function createTypeChecker(host) {
62336
62324
  return context;
62337
62325
  }
62338
62326
  function makeFixingMapperForContext(context) {
62339
- return makeDeferredTypeMapper(map(context.inferences, (i) => i.typeParameter), map(context.inferences, (inference, i) => () => {
62327
+ return makeDeferredTypeMapper(map(context.inferences, (i) => i.typeParameter), map(context.inferences, (inference) => () => {
62340
62328
  if (!inference.isFixed) {
62341
62329
  inferFromIntraExpressionSites(context);
62342
62330
  clearCachedInferences(context.inferences);
62343
62331
  inference.isFixed = true;
62344
62332
  }
62345
- return getInferredType(context, i);
62333
+ return getInferredType(context, inference);
62346
62334
  }));
62347
62335
  }
62348
62336
  function makeNonFixingMapperForContext(context) {
62349
- return makeDeferredTypeMapper(map(context.inferences, (i) => i.typeParameter), map(context.inferences, (_, i) => () => {
62350
- return getInferredType(context, i);
62337
+ return makeDeferredTypeMapper(map(context.inferences, (i) => i.typeParameter), map(context.inferences, (inference) => () => {
62338
+ return getInferredType(context, inference);
62351
62339
  }));
62352
62340
  }
62341
+ function makeFreeTypeVariableMapperForContext(context) {
62342
+ if (!context.freeTypeVariables)
62343
+ return void 0;
62344
+ const baseMapper = getTypeParameterConstraintMapper(map(context.freeTypeVariables, (i) => i.typeParameter));
62345
+ return context.freeTypeVariables.reduceRight(
62346
+ (previous, i) => combineTypeMappers(makeDeferredTypeMapper([i.typeParameter], [() => hasInferenceCandidatesOrDefault(i) ? getInferredType(context, i) : instantiateType(i.typeParameter, baseMapper)]), previous),
62347
+ baseMapper
62348
+ );
62349
+ }
62353
62350
  function clearCachedInferences(inferences) {
62354
62351
  for (const inference of inferences) {
62355
62352
  if (!inference.isFixed) {
@@ -62366,7 +62363,7 @@ function createTypeChecker(host) {
62366
62363
  for (const { node, type } of context.intraExpressionInferenceSites) {
62367
62364
  const contextualType = node.kind === 171 /* MethodDeclaration */ ? getContextualTypeForObjectLiteralMethod(node, 2 /* NoConstraints */) : getContextualType(node, 2 /* NoConstraints */);
62368
62365
  if (contextualType) {
62369
- inferTypes(context.inferences, type, contextualType);
62366
+ inferTypes(context, type, contextualType);
62370
62367
  }
62371
62368
  }
62372
62369
  context.intraExpressionInferenceSites = void 0;
@@ -62401,7 +62398,8 @@ function createTypeChecker(host) {
62401
62398
  return inferences.length ? createInferenceContextWorker(map(inferences, cloneInferenceInfo), context.signature, context.flags, context.compareTypes) : void 0;
62402
62399
  }
62403
62400
  function getMapperFromContext(context) {
62404
- return context && context.mapper;
62401
+ const innerContext = context && last(flattenInferenceContextAlternatives(context));
62402
+ return innerContext && innerContext.mapper && (innerContext.freeTypeVariables ? combineTypeMappers(innerContext.mapper, makeFreeTypeVariableMapperForContext(innerContext)) : innerContext.mapper);
62405
62403
  }
62406
62404
  function couldContainTypeVariables(type) {
62407
62405
  const objectFlags = getObjectFlags(type);
@@ -62501,8 +62499,15 @@ function createTypeChecker(host) {
62501
62499
  const typeParameter = getIndexedAccessType(constraint.type, getTypeParameterFromMappedType(target));
62502
62500
  const templateType = getTemplateTypeFromMappedType(target);
62503
62501
  const inference = createInferenceInfo(typeParameter);
62504
- inferTypes([inference], sourceType, templateType);
62505
- return getTypeFromInference(inference) || unknownType;
62502
+ const context = createInferenceContextWorker(
62503
+ [inference],
62504
+ /*signature*/
62505
+ void 0,
62506
+ 0 /* None */,
62507
+ compareTypesAssignable
62508
+ );
62509
+ inferTypes(context, sourceType, templateType);
62510
+ return getInferredTypes(context, returnFalse)[0] || unknownType;
62506
62511
  }
62507
62512
  function* getUnmatchedProperties(source, target, requireOptionalProperties, matchDiscriminantProperties) {
62508
62513
  const properties = getPropertiesOfType(target);
@@ -62679,7 +62684,15 @@ function createTypeChecker(host) {
62679
62684
  pos = p;
62680
62685
  }
62681
62686
  }
62682
- function inferTypes(inferences, originalSource, originalTarget, priority = 0 /* None */, contravariant = false) {
62687
+ function flattenInferenceContextAlternatives(context) {
62688
+ return context.alternatives ? (context.alternatives.forEach((a) => mergeInferenceContexts(
62689
+ a,
62690
+ context,
62691
+ /*clone*/
62692
+ true
62693
+ )), context.alternatives) : [context];
62694
+ }
62695
+ function inferTypes(context, originalSource, originalTarget, priority = 0 /* None */, contravariant = false) {
62683
62696
  let bivariant = false;
62684
62697
  let propagationType;
62685
62698
  let inferencePriority = 2048 /* MaxValue */;
@@ -62688,7 +62701,21 @@ function createTypeChecker(host) {
62688
62701
  let sourceStack;
62689
62702
  let targetStack;
62690
62703
  let expandingFlags = 0 /* None */;
62704
+ let useOnlyCachedAlternativeRoutes = false;
62691
62705
  inferFromTypes(originalSource, originalTarget);
62706
+ useOnlyCachedAlternativeRoutes = true;
62707
+ const group2 = forkInferenceContext();
62708
+ spawnAlternativeInferenceContext(
62709
+ group2,
62710
+ () => {
62711
+ if (length(context.freeTypeVariables)) {
62712
+ inferFromTypes(originalSource, instantiateType(originalTarget, context.nonFixingMapper));
62713
+ }
62714
+ },
62715
+ /*fork*/
62716
+ false
62717
+ );
62718
+ joinInferenceContext(group2);
62692
62719
  function inferFromTypes(source, target) {
62693
62720
  if (!couldContainTypeVariables(target)) {
62694
62721
  return;
@@ -62749,6 +62776,9 @@ function createTypeChecker(host) {
62749
62776
  if (getObjectFlags(source) & 262144 /* NonInferrableType */ || source === nonInferrableAnyType) {
62750
62777
  return;
62751
62778
  }
62779
+ if (useOnlyCachedAlternativeRoutes && source === target) {
62780
+ return;
62781
+ }
62752
62782
  if (!inference.isFixed) {
62753
62783
  if (inference.priority === void 0 || priority < inference.priority) {
62754
62784
  inference.candidates = void 0;
@@ -62761,16 +62791,16 @@ function createTypeChecker(host) {
62761
62791
  if (contravariant && !bivariant) {
62762
62792
  if (!contains(inference.contraCandidates, candidate)) {
62763
62793
  inference.contraCandidates = append(inference.contraCandidates, candidate);
62764
- clearCachedInferences(inferences);
62794
+ clearCachedInferences(context.inferences);
62765
62795
  }
62766
62796
  } else if (!contains(inference.candidates, candidate)) {
62767
62797
  inference.candidates = append(inference.candidates, candidate);
62768
- clearCachedInferences(inferences);
62798
+ clearCachedInferences(context.inferences);
62769
62799
  }
62770
62800
  }
62771
62801
  if (!(priority & 128 /* ReturnType */) && target.flags & 262144 /* TypeParameter */ && inference.topLevel && !isTypeParameterAtTopLevel(originalTarget, target)) {
62772
62802
  inference.topLevel = false;
62773
- clearCachedInferences(inferences);
62803
+ clearCachedInferences(context.inferences);
62774
62804
  }
62775
62805
  }
62776
62806
  inferencePriority = Math.min(inferencePriority, priority);
@@ -62938,7 +62968,12 @@ function createTypeChecker(host) {
62938
62968
  }
62939
62969
  function getInferenceInfoForType(type) {
62940
62970
  if (type.flags & 8650752 /* TypeVariable */) {
62941
- for (const inference of inferences) {
62971
+ for (const inference of context.inferences) {
62972
+ if (type === inference.typeParameter) {
62973
+ return inference;
62974
+ }
62975
+ }
62976
+ for (const inference of context.freeTypeVariables || []) {
62942
62977
  if (type === inference.typeParameter) {
62943
62978
  return inference;
62944
62979
  }
@@ -63219,17 +63254,88 @@ function createTypeChecker(host) {
63219
63254
  }
63220
63255
  }
63221
63256
  }
63257
+ function forkInferenceContext() {
63258
+ return [];
63259
+ }
63260
+ function spawnAlternativeInferenceContext(group3, action, fork = true) {
63261
+ const oldContext = context;
63262
+ flattenInferenceContextAlternatives(context).forEach((alternative) => {
63263
+ const newContext = fork ? cloneInferenceContext(alternative) : alternative;
63264
+ context = newContext;
63265
+ action();
63266
+ context = oldContext;
63267
+ group3.push(...flattenInferenceContextAlternatives(newContext));
63268
+ });
63269
+ }
63270
+ function joinInferenceContext(group3) {
63271
+ group3 = group3.length < 10 ? deduplicate(group3, compareInferenceContext) : group3;
63272
+ if (group3.length === 1) {
63273
+ mergeInferenceContexts(context, group3[0]);
63274
+ context.freeTypeVariables = group3[0].freeTypeVariables;
63275
+ context.freeTypeVariableSourceSignatures = group3[0].freeTypeVariableSourceSignatures;
63276
+ context.inferredTypeParameters = group3[0].inferredTypeParameters;
63277
+ context.flags = group3[0].flags;
63278
+ context.alternatives = void 0;
63279
+ return;
63280
+ }
63281
+ context.alternatives = group3;
63282
+ }
63283
+ function compareInferenceContext(a, b) {
63284
+ return a.compareTypes === b.compareTypes && a.flags === b.flags && a.inferredTypeParameters === b.inferredTypeParameters && a.intraExpressionInferenceSites === b.intraExpressionInferenceSites && a.signature === b.signature && compareInferencesIdentical(a, a.inferences, b, b.inferences) && compareInferencesIdentical(a, a.freeTypeVariables, b, b.freeTypeVariables);
63285
+ }
63286
+ function compareInferencesIdentical(ctxA, a, ctxB, b) {
63287
+ if (length(a) !== length(b))
63288
+ return false;
63289
+ if (length(a) === 0)
63290
+ return true;
63291
+ for (let i = 0; i < length(a); i++) {
63292
+ if (a[i].typeParameter !== b[i].typeParameter || a[i].impliedArity !== b[i].impliedArity || a[i].isFixed !== b[i].isFixed || a[i].priority !== b[i].priority || a[i].topLevel !== b[i].topLevel || forEach(a, (_, i2) => getInferredType(ctxA, a[i2]) !== getInferredType(ctxB, b[i2])))
63293
+ return false;
63294
+ }
63295
+ return true;
63296
+ }
63222
63297
  function inferFromSignatures(source, target, kind) {
63298
+ var _a2, _b;
63223
63299
  const sourceSignatures = getSignaturesOfType(source, kind);
63224
63300
  const targetSignatures = getSignaturesOfType(target, kind);
63225
63301
  const sourceLen = sourceSignatures.length;
63226
63302
  const targetLen = targetSignatures.length;
63227
- const len = sourceLen < targetLen ? sourceLen : targetLen;
63228
- for (let i = 0; i < len; i++) {
63229
- inferFromSignature(getBaseSignature(sourceSignatures[sourceLen - len + i]), getErasedSignature(targetSignatures[targetLen - len + i]));
63303
+ if (targetLen === 1 && sourceLen > 1) {
63304
+ const group3 = forkInferenceContext();
63305
+ for (let i = 0; i < sourceLen; i++) {
63306
+ if (useOnlyCachedAlternativeRoutes && !((_b = (_a2 = context.freeTypeVariableSourceSignatures) == null ? void 0 : _a2.get(last(sourceStack))) == null ? void 0 : _b.get(sourceSignatures[i]))) {
63307
+ continue;
63308
+ }
63309
+ spawnAlternativeInferenceContext(
63310
+ group3,
63311
+ () => inferFromSignature(sourceSignatures[i], targetSignatures[0])
63312
+ );
63313
+ }
63314
+ joinInferenceContext(group3);
63315
+ } else {
63316
+ const len = sourceLen < targetLen ? sourceLen : targetLen;
63317
+ for (let i = 0; i < len; i++) {
63318
+ inferFromSignature(sourceSignatures[sourceLen - len + i], targetSignatures[targetLen - len + i]);
63319
+ }
63230
63320
  }
63231
63321
  }
63232
63322
  function inferFromSignature(source, target) {
63323
+ target = getErasedSignature(target);
63324
+ if (source.typeParameters) {
63325
+ let cache = (context.freeTypeVariableSourceSignatures || (context.freeTypeVariableSourceSignatures = /* @__PURE__ */ new Map())).get(last(sourceStack));
63326
+ if (!cache) {
63327
+ context.freeTypeVariableSourceSignatures.set(last(sourceStack), cache = /* @__PURE__ */ new Map());
63328
+ }
63329
+ const cached = cache.get(source);
63330
+ if (cached) {
63331
+ source = cached;
63332
+ } else {
63333
+ const originalSignature = source;
63334
+ source = instantiateSignature(source, makeUnaryTypeMapper(unknownType, unknownType));
63335
+ cache.set(originalSignature, source);
63336
+ (context.freeTypeVariables || (context.freeTypeVariables = [])).push(...map(source.typeParameters, createInferenceInfo));
63337
+ }
63338
+ }
63233
63339
  const saveBivariant = bivariant;
63234
63340
  const kind = target.declaration ? target.declaration.kind : 0 /* Unknown */;
63235
63341
  bivariant = bivariant || kind === 171 /* MethodDeclaration */ || kind === 170 /* MethodSignature */ || kind === 173 /* Constructor */;
@@ -63304,8 +63410,7 @@ function createTypeChecker(host) {
63304
63410
  const unwidenedType = inference.priority & 416 /* PriorityImpliesCombination */ ? getUnionType(baseCandidates, 2 /* Subtype */) : getCommonSupertype(baseCandidates);
63305
63411
  return getWidenedType(unwidenedType);
63306
63412
  }
63307
- function getInferredType(context, index) {
63308
- const inference = context.inferences[index];
63413
+ function getInferredType(context, inference) {
63309
63414
  if (!inference.inferredType) {
63310
63415
  let inferredType;
63311
63416
  const signature = context.signature;
@@ -63321,7 +63426,7 @@ function createTypeChecker(host) {
63321
63426
  } else {
63322
63427
  const defaultType = getDefaultFromTypeParameter(inference.typeParameter);
63323
63428
  if (defaultType) {
63324
- inferredType = instantiateType(defaultType, mergeTypeMappers(createBackreferenceMapper(context, index), context.nonFixingMapper));
63429
+ inferredType = instantiateType(defaultType, mergeTypeMappers(createBackreferenceMapper(context, inference), context.nonFixingMapper));
63325
63430
  }
63326
63431
  }
63327
63432
  } else {
@@ -63341,12 +63446,24 @@ function createTypeChecker(host) {
63341
63446
  function getDefaultTypeArgumentType(isInJavaScriptFile) {
63342
63447
  return isInJavaScriptFile ? anyType : unknownType;
63343
63448
  }
63344
- function getInferredTypes(context) {
63345
- const result = [];
63346
- for (let i = 0; i < context.inferences.length; i++) {
63347
- result.push(getInferredType(context, i));
63449
+ function getInferredTypes(context, accept) {
63450
+ const alternatives = flattenInferenceContextAlternatives(context);
63451
+ let finalAlternative;
63452
+ for (let a = alternatives.length - 1; a >= 0; a--) {
63453
+ const context2 = alternatives[a];
63454
+ const freeTypeVariableMapper = makeFreeTypeVariableMapperForContext(context2);
63455
+ const result = [];
63456
+ for (const inference of context2.inferences) {
63457
+ result.push(instantiateType(getInferredType(context2, inference), freeTypeVariableMapper));
63458
+ }
63459
+ if (alternatives.length === 1 || accept(result)) {
63460
+ return result;
63461
+ }
63462
+ if (!finalAlternative) {
63463
+ finalAlternative = result;
63464
+ }
63348
63465
  }
63349
- return result;
63466
+ return finalAlternative;
63350
63467
  }
63351
63468
  function getCannotFindNameDiagnosticForName(node) {
63352
63469
  switch (node.escapedText) {
@@ -66724,8 +66841,11 @@ function createTypeChecker(host) {
66724
66841
  function instantiateContextualType(contextualType, node, contextFlags) {
66725
66842
  if (contextualType && maybeTypeOfKind(contextualType, 465829888 /* Instantiable */)) {
66726
66843
  const inferenceContext = getInferenceContext(node);
66727
- if (inferenceContext && contextFlags & 1 /* Signature */ && some(inferenceContext.inferences, hasInferenceCandidatesOrDefault)) {
66728
- return instantiateInstantiableTypes(contextualType, inferenceContext.nonFixingMapper);
66844
+ if (inferenceContext && contextFlags & 1 /* Signature */ && some(flatMap(flattenInferenceContextAlternatives(inferenceContext), (c) => c.inferences), hasInferenceCandidatesOrDefault)) {
66845
+ return getUnionType(map(
66846
+ flattenInferenceContextAlternatives(inferenceContext),
66847
+ (c) => instantiateInstantiableTypes(contextualType, c.nonFixingMapper)
66848
+ ));
66729
66849
  }
66730
66850
  if (inferenceContext == null ? void 0 : inferenceContext.returnMapper) {
66731
66851
  const type = instantiateInstantiableTypes(contextualType, inferenceContext.returnMapper);
@@ -69084,23 +69204,23 @@ function createTypeChecker(host) {
69084
69204
  function instantiateSignatureInContextOf(signature, contextualSignature, inferenceContext, compareTypes) {
69085
69205
  const context = createInferenceContext(signature.typeParameters, signature, 0 /* None */, compareTypes);
69086
69206
  const restType = getEffectiveRestType(contextualSignature);
69087
- const mapper = inferenceContext && (restType && restType.flags & 262144 /* TypeParameter */ ? inferenceContext.nonFixingMapper : inferenceContext.mapper);
69207
+ const mapper = inferenceContext && (restType && restType.flags & 262144 /* TypeParameter */ ? inferenceContext.nonFixingMapper : getMapperFromContext(inferenceContext));
69088
69208
  const sourceSignature = mapper ? instantiateSignature(contextualSignature, mapper) : contextualSignature;
69089
69209
  applyToParameterTypes(sourceSignature, signature, (source, target) => {
69090
- inferTypes(context.inferences, source, target);
69210
+ inferTypes(context, source, target);
69091
69211
  });
69092
69212
  if (!inferenceContext) {
69093
69213
  applyToReturnTypes(contextualSignature, signature, (source, target) => {
69094
- inferTypes(context.inferences, source, target, 128 /* ReturnType */);
69214
+ inferTypes(context, source, target, 128 /* ReturnType */);
69095
69215
  });
69096
69216
  }
69097
- return getSignatureInstantiation(signature, getInferredTypes(context), isInJSFile(contextualSignature.declaration));
69217
+ return getSignatureInstantiation(signature, getInferredTypes(context, returnFalse), isInJSFile(contextualSignature.declaration));
69098
69218
  }
69099
- function inferJsxTypeArguments(node, signature, checkMode, context) {
69219
+ function inferJsxTypeArguments(node, signature, checkMode, context, accept) {
69100
69220
  const paramType = getEffectiveFirstArgumentForJsxSignature(signature, node);
69101
69221
  const checkAttrType = checkExpressionWithContextualType(node.attributes, paramType, context, checkMode);
69102
- inferTypes(context.inferences, checkAttrType, paramType);
69103
- return getInferredTypes(context);
69222
+ inferTypes(context, checkAttrType, paramType);
69223
+ return getInferredTypes(context, accept);
69104
69224
  }
69105
69225
  function getThisArgumentType(thisArgumentNode) {
69106
69226
  if (!thisArgumentNode) {
@@ -69109,9 +69229,9 @@ function createTypeChecker(host) {
69109
69229
  const thisArgumentType = checkExpression(thisArgumentNode);
69110
69230
  return isOptionalChainRoot(thisArgumentNode.parent) ? getNonNullableType(thisArgumentType) : isOptionalChain(thisArgumentNode.parent) ? removeOptionalTypeMarker(thisArgumentType) : thisArgumentType;
69111
69231
  }
69112
- function inferTypeArguments(node, signature, args, checkMode, context) {
69232
+ function inferTypeArguments(node, signature, args, checkMode, context, accept) {
69113
69233
  if (isJsxOpeningLikeElement(node)) {
69114
- return inferJsxTypeArguments(node, signature, checkMode, context);
69234
+ return inferJsxTypeArguments(node, signature, checkMode, context, accept);
69115
69235
  }
69116
69236
  if (node.kind !== 167 /* Decorator */) {
69117
69237
  const skipBindingPatterns = every(signature.typeParameters, (p) => !!getDefaultFromTypeParameter(p));
@@ -69126,11 +69246,11 @@ function createTypeChecker(host) {
69126
69246
  const instantiatedType = instantiateType(contextualType, outerMapper);
69127
69247
  const contextualSignature = getSingleCallSignature(instantiatedType);
69128
69248
  const inferenceSourceType = contextualSignature && contextualSignature.typeParameters ? getOrCreateTypeFromSignature(getSignatureInstantiationWithoutFillingInTypeArguments(contextualSignature, contextualSignature.typeParameters)) : instantiatedType;
69129
- inferTypes(context.inferences, inferenceSourceType, inferenceTargetType, 128 /* ReturnType */);
69249
+ inferTypes(context, inferenceSourceType, inferenceTargetType, 128 /* ReturnType */);
69130
69250
  }
69131
69251
  const returnContext = createInferenceContext(signature.typeParameters, signature, context.flags);
69132
69252
  const returnSourceType = instantiateType(contextualType, outerContext && outerContext.returnMapper);
69133
- inferTypes(returnContext.inferences, returnSourceType, inferenceTargetType);
69253
+ inferTypes(returnContext, returnSourceType, inferenceTargetType);
69134
69254
  context.returnMapper = some(returnContext.inferences, hasInferenceCandidates) ? getMapperFromContext(cloneInferredPartOfContext(returnContext)) : void 0;
69135
69255
  }
69136
69256
  }
@@ -69146,7 +69266,7 @@ function createTypeChecker(host) {
69146
69266
  const thisType = getThisTypeOfSignature(signature);
69147
69267
  if (thisType && couldContainTypeVariables(thisType)) {
69148
69268
  const thisArgumentNode = getThisArgumentOfCall(node);
69149
- inferTypes(context.inferences, getThisArgumentType(thisArgumentNode), thisType);
69269
+ inferTypes(context, getThisArgumentType(thisArgumentNode), thisType);
69150
69270
  }
69151
69271
  for (let i = 0; i < argCount; i++) {
69152
69272
  const arg = args[i];
@@ -69154,15 +69274,15 @@ function createTypeChecker(host) {
69154
69274
  const paramType = getTypeAtPosition(signature, i);
69155
69275
  if (couldContainTypeVariables(paramType)) {
69156
69276
  const argType = checkExpressionWithContextualType(arg, paramType, context, checkMode);
69157
- inferTypes(context.inferences, argType, paramType);
69277
+ inferTypes(context, argType, paramType);
69158
69278
  }
69159
69279
  }
69160
69280
  }
69161
69281
  if (restType && couldContainTypeVariables(restType)) {
69162
69282
  const spreadType = getSpreadArgumentType(args, argCount, args.length, restType, context, checkMode);
69163
- inferTypes(context.inferences, spreadType, restType);
69283
+ inferTypes(context, spreadType, restType);
69164
69284
  }
69165
- return getInferredTypes(context);
69285
+ return getInferredTypes(context, accept);
69166
69286
  }
69167
69287
  function getMutableArrayOrTupleType(type) {
69168
69288
  return type.flags & 1048576 /* Union */ ? mapType(type, getMutableArrayOrTupleType) : type.flags & 1 /* Any */ || isMutableArrayOrTuple(getBaseConstraintOfType(type) || type) ? type : isTupleType(type) ? createTupleType(
@@ -69929,6 +70049,26 @@ function createTypeChecker(host) {
69929
70049
  }
69930
70050
  let checkCandidate;
69931
70051
  let inferenceContext;
70052
+ const acceptor = (types) => {
70053
+ const checkCandidate2 = getSignatureInstantiation(candidate, types, isInJSFile(candidate.declaration), inferenceContext && inferenceContext.inferredTypeParameters);
70054
+ if (getNonArrayRestType(candidate) && !hasCorrectArity(node, args, checkCandidate2, signatureHelpTrailingComma2)) {
70055
+ return false;
70056
+ }
70057
+ if (getSignatureApplicabilityError(
70058
+ node,
70059
+ args,
70060
+ checkCandidate2,
70061
+ relation,
70062
+ argCheckMode,
70063
+ /*reportErrors*/
70064
+ false,
70065
+ /*containingMessageChain*/
70066
+ void 0
70067
+ )) {
70068
+ return false;
70069
+ }
70070
+ return true;
70071
+ };
69932
70072
  if (candidate.typeParameters) {
69933
70073
  let typeArgumentTypes;
69934
70074
  if (some(typeArguments)) {
@@ -69949,7 +70089,7 @@ function createTypeChecker(host) {
69949
70089
  /*flags*/
69950
70090
  isInJSFile(node) ? 2 /* AnyDefault */ : 0 /* None */
69951
70091
  );
69952
- typeArgumentTypes = inferTypeArguments(node, candidate, args, argCheckMode | 8 /* SkipGenericFunctions */, inferenceContext);
70092
+ typeArgumentTypes = inferTypeArguments(node, candidate, args, argCheckMode | 8 /* SkipGenericFunctions */, inferenceContext, acceptor);
69953
70093
  argCheckMode |= inferenceContext.flags & 4 /* SkippedGenericFunction */ ? 8 /* SkipGenericFunctions */ : 0 /* Normal */;
69954
70094
  }
69955
70095
  checkCandidate = getSignatureInstantiation(candidate, typeArgumentTypes, isInJSFile(candidate.declaration), inferenceContext && inferenceContext.inferredTypeParameters);
@@ -69977,7 +70117,7 @@ function createTypeChecker(host) {
69977
70117
  if (argCheckMode) {
69978
70118
  argCheckMode = checkMode & 32 /* IsForStringLiteralArgumentCompletions */;
69979
70119
  if (inferenceContext) {
69980
- const typeArgumentTypes = inferTypeArguments(node, candidate, args, argCheckMode, inferenceContext);
70120
+ const typeArgumentTypes = inferTypeArguments(node, candidate, args, argCheckMode, inferenceContext, acceptor);
69981
70121
  checkCandidate = getSignatureInstantiation(candidate, typeArgumentTypes, isInJSFile(candidate.declaration), inferenceContext.inferredTypeParameters);
69982
70122
  if (getNonArrayRestType(candidate) && !hasCorrectArity(node, args, checkCandidate, signatureHelpTrailingComma2)) {
69983
70123
  candidateForArgumentArityError = checkCandidate;
@@ -70087,7 +70227,7 @@ function createTypeChecker(host) {
70087
70227
  /*flags*/
70088
70228
  isInJSFile(node) ? 2 /* AnyDefault */ : 0 /* None */
70089
70229
  );
70090
- const typeArgumentTypes = inferTypeArguments(node, candidate, args, checkMode | 4 /* SkipContextSensitive */ | 8 /* SkipGenericFunctions */, inferenceContext);
70230
+ const typeArgumentTypes = inferTypeArguments(node, candidate, args, checkMode | 4 /* SkipContextSensitive */ | 8 /* SkipGenericFunctions */, inferenceContext, returnFalse);
70091
70231
  return createSignatureInstantiation(candidate, typeArgumentTypes);
70092
70232
  }
70093
70233
  function getLongestCandidateIndex(candidates, argsCount) {
@@ -71355,7 +71495,7 @@ function createTypeChecker(host) {
71355
71495
  if (declaration.type) {
71356
71496
  const typeNode = getEffectiveTypeAnnotationNode(declaration);
71357
71497
  if (typeNode) {
71358
- inferTypes(inferenceContext.inferences, getTypeFromTypeNode(typeNode), getTypeAtPosition(context, i));
71498
+ inferTypes(inferenceContext, getTypeFromTypeNode(typeNode), getTypeAtPosition(context, i));
71359
71499
  }
71360
71500
  }
71361
71501
  }
@@ -72067,7 +72207,7 @@ function createTypeChecker(host) {
72067
72207
  instantiatedContextualSignature = instantiateSignature(contextualSignature, inferenceContext.nonFixingMapper);
72068
72208
  }
72069
72209
  }
72070
- instantiatedContextualSignature || (instantiatedContextualSignature = inferenceContext ? instantiateSignature(contextualSignature, inferenceContext.mapper) : contextualSignature);
72210
+ instantiatedContextualSignature || (instantiatedContextualSignature = inferenceContext ? instantiateSignature(contextualSignature, getMapperFromContext(inferenceContext)) : contextualSignature);
72071
72211
  assignContextualParameterTypes(signature, instantiatedContextualSignature);
72072
72212
  } else {
72073
72213
  assignNonContextualParameterTypes(signature);
@@ -73448,7 +73588,7 @@ function createTypeChecker(host) {
73448
73588
  return isAssertionExpression(parent) && isConstTypeReference(parent.type) || isJSDocTypeAssertion(parent) && isConstTypeReference(getJSDocTypeAssertionType(parent)) || isValidConstAssertionArgument(node) && isConstTypeParameterContext(node) || (isParenthesizedExpression(parent) || isArrayLiteralExpression(parent) || isSpreadElement(parent)) && isConstContext(parent) || (isPropertyAssignment(parent) || isShorthandPropertyAssignment(parent) || isTemplateSpan(parent)) && isConstContext(parent.parent);
73449
73589
  }
73450
73590
  function isConstTypeParameterContext(node) {
73451
- const contextualType = getContextualType(node, 0 /* None */);
73591
+ const contextualType = getContextualType(node, 1 /* Signature */);
73452
73592
  return !!contextualType && someType(contextualType, isConstTypeVariable);
73453
73593
  }
73454
73594
  function checkExpressionForMutableLocation(node, checkMode, forceTuple) {
@@ -73513,10 +73653,11 @@ function createTypeChecker(host) {
73513
73653
  if (returnSignature && !returnSignature.typeParameters && !every(context.inferences, hasInferenceCandidates)) {
73514
73654
  const uniqueTypeParameters = getUniqueTypeParameters(context, signature.typeParameters);
73515
73655
  const instantiatedSignature = getSignatureInstantiationWithoutFillingInTypeArguments(signature, uniqueTypeParameters);
73516
- const inferences = map(context.inferences, (info) => createInferenceInfo(info.typeParameter));
73656
+ const subcontext = cloneInferenceContext(context);
73657
+ subcontext.inferences = map(context.inferences, (info) => createInferenceInfo(info.typeParameter));
73517
73658
  applyToParameterTypes(instantiatedSignature, contextualSignature, (source, target) => {
73518
73659
  inferTypes(
73519
- inferences,
73660
+ subcontext,
73520
73661
  source,
73521
73662
  target,
73522
73663
  /*priority*/
@@ -73525,12 +73666,12 @@ function createTypeChecker(host) {
73525
73666
  true
73526
73667
  );
73527
73668
  });
73528
- if (some(inferences, hasInferenceCandidates)) {
73669
+ if (some(subcontext.inferences, hasInferenceCandidates)) {
73529
73670
  applyToReturnTypes(instantiatedSignature, contextualSignature, (source, target) => {
73530
- inferTypes(inferences, source, target);
73671
+ inferTypes(subcontext, source, target);
73531
73672
  });
73532
- if (!hasOverlappingInferences(context.inferences, inferences)) {
73533
- mergeInferences(context.inferences, inferences);
73673
+ if (!hasOverlappingInferences(context.inferences, subcontext.inferences)) {
73674
+ mergeInferenceContexts(context, subcontext);
73534
73675
  context.inferredTypeParameters = concatenate(context.inferredTypeParameters, uniqueTypeParameters);
73535
73676
  return getOrCreateTypeFromSignature(instantiatedSignature);
73536
73677
  }
@@ -73563,13 +73704,22 @@ function createTypeChecker(host) {
73563
73704
  }
73564
73705
  return false;
73565
73706
  }
73566
- function mergeInferences(target, source) {
73707
+ function mergeInferences(target, source, clone2 = false) {
73567
73708
  for (let i = 0; i < target.length; i++) {
73568
73709
  if (!hasInferenceCandidates(target[i]) && hasInferenceCandidates(source[i])) {
73569
- target[i] = source[i];
73710
+ target[i] = clone2 ? {
73711
+ ...source[i],
73712
+ candidates: source[i].candidates && [...source[i].candidates],
73713
+ contraCandidates: source[i].contraCandidates && [...source[i].contraCandidates]
73714
+ } : source[i];
73570
73715
  }
73571
73716
  }
73572
73717
  }
73718
+ function mergeInferenceContexts(target, source, cloneInferences = false) {
73719
+ mergeInferences(target.inferences, source.inferences, cloneInferences);
73720
+ target.mapper = makeFixingMapperForContext(target);
73721
+ target.nonFixingMapper = makeNonFixingMapperForContext(target);
73722
+ }
73573
73723
  function getUniqueTypeParameters(context, typeParameters) {
73574
73724
  const result = [];
73575
73725
  let oldTypeParameters;