@typescript-deploys/pr-build 5.0.0-pr-52899-2 → 5.0.0-pr-52944-9

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
@@ -7825,8 +7825,7 @@ var Diagnostics = {
7825
7825
  _0_is_possibly_undefined: diag(18048, 1 /* Error */, "_0_is_possibly_undefined_18048", "'{0}' is possibly 'undefined'."),
7826
7826
  _0_is_possibly_null_or_undefined: diag(18049, 1 /* Error */, "_0_is_possibly_null_or_undefined_18049", "'{0}' is possibly 'null' or 'undefined'."),
7827
7827
  The_value_0_cannot_be_used_here: diag(18050, 1 /* Error */, "The_value_0_cannot_be_used_here_18050", "The value '{0}' cannot be used here."),
7828
- Compiler_option_0_cannot_be_given_an_empty_string: diag(18051, 1 /* Error */, "Compiler_option_0_cannot_be_given_an_empty_string_18051", "Compiler option '{0}' cannot be given an empty string."),
7829
- Add_missing_comma_for_an_object_member_completion_0: diag(18052, 3 /* Message */, "Add_missing_comma_for_an_object_member_completion_0_18052", "Add missing comma for an object member completion '{0}'.")
7828
+ Compiler_option_0_cannot_be_given_an_empty_string: diag(18051, 1 /* Error */, "Compiler_option_0_cannot_be_given_an_empty_string_18051", "Compiler option '{0}' cannot be given an empty string.")
7830
7829
  };
7831
7830
 
7832
7831
  // src/compiler/scanner.ts
@@ -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) {
@@ -60471,9 +60461,10 @@ function createTypeChecker(host) {
60471
60461
  0 /* None */,
60472
60462
  isRelatedToWorker
60473
60463
  );
60474
- inferTypes(ctx.inferences, target2.extendsType, sourceExtends, 512 /* NoConstraints */ | 1024 /* AlwaysStrict */);
60475
- sourceExtends = instantiateType(sourceExtends, ctx.mapper);
60476
- 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;
60477
60468
  }
60478
60469
  if (isTypeIdenticalTo(sourceExtends, target2.extendsType) && (isRelatedTo(source2.checkType, target2.checkType, 3 /* Both */) || isRelatedTo(target2.checkType, source2.checkType, 3 /* Both */))) {
60479
60470
  if (result2 = isRelatedTo(instantiateType(getTrueTypeFromConditionalType(source2), mapper), getTrueTypeFromConditionalType(target2), 3 /* Both */, reportErrors2)) {
@@ -62311,7 +62302,12 @@ function createTypeChecker(host) {
62311
62302
  return createInferenceContextWorker(typeParameters.map(createInferenceInfo), signature, flags, compareTypes || compareTypesAssignable);
62312
62303
  }
62313
62304
  function cloneInferenceContext(context, extraFlags = 0) {
62314
- 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;
62315
62311
  }
62316
62312
  function createInferenceContextWorker(inferences, signature, flags, compareTypes) {
62317
62313
  const context = {
@@ -62328,20 +62324,29 @@ function createTypeChecker(host) {
62328
62324
  return context;
62329
62325
  }
62330
62326
  function makeFixingMapperForContext(context) {
62331
- 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) => () => {
62332
62328
  if (!inference.isFixed) {
62333
62329
  inferFromIntraExpressionSites(context);
62334
62330
  clearCachedInferences(context.inferences);
62335
62331
  inference.isFixed = true;
62336
62332
  }
62337
- return getInferredType(context, i);
62333
+ return getInferredType(context, inference);
62338
62334
  }));
62339
62335
  }
62340
62336
  function makeNonFixingMapperForContext(context) {
62341
- return makeDeferredTypeMapper(map(context.inferences, (i) => i.typeParameter), map(context.inferences, (_, i) => () => {
62342
- return getInferredType(context, i);
62337
+ return makeDeferredTypeMapper(map(context.inferences, (i) => i.typeParameter), map(context.inferences, (inference) => () => {
62338
+ return getInferredType(context, inference);
62343
62339
  }));
62344
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
+ }
62345
62350
  function clearCachedInferences(inferences) {
62346
62351
  for (const inference of inferences) {
62347
62352
  if (!inference.isFixed) {
@@ -62358,7 +62363,7 @@ function createTypeChecker(host) {
62358
62363
  for (const { node, type } of context.intraExpressionInferenceSites) {
62359
62364
  const contextualType = node.kind === 171 /* MethodDeclaration */ ? getContextualTypeForObjectLiteralMethod(node, 2 /* NoConstraints */) : getContextualType(node, 2 /* NoConstraints */);
62360
62365
  if (contextualType) {
62361
- inferTypes(context.inferences, type, contextualType);
62366
+ inferTypes(context, type, contextualType);
62362
62367
  }
62363
62368
  }
62364
62369
  context.intraExpressionInferenceSites = void 0;
@@ -62393,7 +62398,8 @@ function createTypeChecker(host) {
62393
62398
  return inferences.length ? createInferenceContextWorker(map(inferences, cloneInferenceInfo), context.signature, context.flags, context.compareTypes) : void 0;
62394
62399
  }
62395
62400
  function getMapperFromContext(context) {
62396
- 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);
62397
62403
  }
62398
62404
  function couldContainTypeVariables(type) {
62399
62405
  const objectFlags = getObjectFlags(type);
@@ -62493,8 +62499,15 @@ function createTypeChecker(host) {
62493
62499
  const typeParameter = getIndexedAccessType(constraint.type, getTypeParameterFromMappedType(target));
62494
62500
  const templateType = getTemplateTypeFromMappedType(target);
62495
62501
  const inference = createInferenceInfo(typeParameter);
62496
- inferTypes([inference], sourceType, templateType);
62497
- 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;
62498
62511
  }
62499
62512
  function* getUnmatchedProperties(source, target, requireOptionalProperties, matchDiscriminantProperties) {
62500
62513
  const properties = getPropertiesOfType(target);
@@ -62671,7 +62684,15 @@ function createTypeChecker(host) {
62671
62684
  pos = p;
62672
62685
  }
62673
62686
  }
62674
- 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) {
62675
62696
  let bivariant = false;
62676
62697
  let propagationType;
62677
62698
  let inferencePriority = 2048 /* MaxValue */;
@@ -62680,7 +62701,21 @@ function createTypeChecker(host) {
62680
62701
  let sourceStack;
62681
62702
  let targetStack;
62682
62703
  let expandingFlags = 0 /* None */;
62704
+ let useOnlyCachedAlternativeRoutes = false;
62683
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);
62684
62719
  function inferFromTypes(source, target) {
62685
62720
  if (!couldContainTypeVariables(target)) {
62686
62721
  return;
@@ -62741,6 +62776,9 @@ function createTypeChecker(host) {
62741
62776
  if (getObjectFlags(source) & 262144 /* NonInferrableType */ || source === nonInferrableAnyType) {
62742
62777
  return;
62743
62778
  }
62779
+ if (useOnlyCachedAlternativeRoutes && source === target) {
62780
+ return;
62781
+ }
62744
62782
  if (!inference.isFixed) {
62745
62783
  if (inference.priority === void 0 || priority < inference.priority) {
62746
62784
  inference.candidates = void 0;
@@ -62753,16 +62791,16 @@ function createTypeChecker(host) {
62753
62791
  if (contravariant && !bivariant) {
62754
62792
  if (!contains(inference.contraCandidates, candidate)) {
62755
62793
  inference.contraCandidates = append(inference.contraCandidates, candidate);
62756
- clearCachedInferences(inferences);
62794
+ clearCachedInferences(context.inferences);
62757
62795
  }
62758
62796
  } else if (!contains(inference.candidates, candidate)) {
62759
62797
  inference.candidates = append(inference.candidates, candidate);
62760
- clearCachedInferences(inferences);
62798
+ clearCachedInferences(context.inferences);
62761
62799
  }
62762
62800
  }
62763
62801
  if (!(priority & 128 /* ReturnType */) && target.flags & 262144 /* TypeParameter */ && inference.topLevel && !isTypeParameterAtTopLevel(originalTarget, target)) {
62764
62802
  inference.topLevel = false;
62765
- clearCachedInferences(inferences);
62803
+ clearCachedInferences(context.inferences);
62766
62804
  }
62767
62805
  }
62768
62806
  inferencePriority = Math.min(inferencePriority, priority);
@@ -62930,7 +62968,12 @@ function createTypeChecker(host) {
62930
62968
  }
62931
62969
  function getInferenceInfoForType(type) {
62932
62970
  if (type.flags & 8650752 /* TypeVariable */) {
62933
- 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 || []) {
62934
62977
  if (type === inference.typeParameter) {
62935
62978
  return inference;
62936
62979
  }
@@ -63211,17 +63254,88 @@ function createTypeChecker(host) {
63211
63254
  }
63212
63255
  }
63213
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
+ }
63214
63297
  function inferFromSignatures(source, target, kind) {
63298
+ var _a2, _b;
63215
63299
  const sourceSignatures = getSignaturesOfType(source, kind);
63216
63300
  const targetSignatures = getSignaturesOfType(target, kind);
63217
63301
  const sourceLen = sourceSignatures.length;
63218
63302
  const targetLen = targetSignatures.length;
63219
- const len = sourceLen < targetLen ? sourceLen : targetLen;
63220
- for (let i = 0; i < len; i++) {
63221
- 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
+ }
63222
63320
  }
63223
63321
  }
63224
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
+ }
63225
63339
  const saveBivariant = bivariant;
63226
63340
  const kind = target.declaration ? target.declaration.kind : 0 /* Unknown */;
63227
63341
  bivariant = bivariant || kind === 171 /* MethodDeclaration */ || kind === 170 /* MethodSignature */ || kind === 173 /* Constructor */;
@@ -63296,8 +63410,7 @@ function createTypeChecker(host) {
63296
63410
  const unwidenedType = inference.priority & 416 /* PriorityImpliesCombination */ ? getUnionType(baseCandidates, 2 /* Subtype */) : getCommonSupertype(baseCandidates);
63297
63411
  return getWidenedType(unwidenedType);
63298
63412
  }
63299
- function getInferredType(context, index) {
63300
- const inference = context.inferences[index];
63413
+ function getInferredType(context, inference) {
63301
63414
  if (!inference.inferredType) {
63302
63415
  let inferredType;
63303
63416
  const signature = context.signature;
@@ -63313,7 +63426,7 @@ function createTypeChecker(host) {
63313
63426
  } else {
63314
63427
  const defaultType = getDefaultFromTypeParameter(inference.typeParameter);
63315
63428
  if (defaultType) {
63316
- inferredType = instantiateType(defaultType, mergeTypeMappers(createBackreferenceMapper(context, index), context.nonFixingMapper));
63429
+ inferredType = instantiateType(defaultType, mergeTypeMappers(createBackreferenceMapper(context, inference), context.nonFixingMapper));
63317
63430
  }
63318
63431
  }
63319
63432
  } else {
@@ -63333,12 +63446,24 @@ function createTypeChecker(host) {
63333
63446
  function getDefaultTypeArgumentType(isInJavaScriptFile) {
63334
63447
  return isInJavaScriptFile ? anyType : unknownType;
63335
63448
  }
63336
- function getInferredTypes(context) {
63337
- const result = [];
63338
- for (let i = 0; i < context.inferences.length; i++) {
63339
- 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
+ }
63340
63465
  }
63341
- return result;
63466
+ return finalAlternative;
63342
63467
  }
63343
63468
  function getCannotFindNameDiagnosticForName(node) {
63344
63469
  switch (node.escapedText) {
@@ -66716,8 +66841,11 @@ function createTypeChecker(host) {
66716
66841
  function instantiateContextualType(contextualType, node, contextFlags) {
66717
66842
  if (contextualType && maybeTypeOfKind(contextualType, 465829888 /* Instantiable */)) {
66718
66843
  const inferenceContext = getInferenceContext(node);
66719
- if (inferenceContext && contextFlags & 1 /* Signature */ && some(inferenceContext.inferences, hasInferenceCandidatesOrDefault)) {
66720
- 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
+ ));
66721
66849
  }
66722
66850
  if (inferenceContext == null ? void 0 : inferenceContext.returnMapper) {
66723
66851
  const type = instantiateInstantiableTypes(contextualType, inferenceContext.returnMapper);
@@ -69076,23 +69204,23 @@ function createTypeChecker(host) {
69076
69204
  function instantiateSignatureInContextOf(signature, contextualSignature, inferenceContext, compareTypes) {
69077
69205
  const context = createInferenceContext(signature.typeParameters, signature, 0 /* None */, compareTypes);
69078
69206
  const restType = getEffectiveRestType(contextualSignature);
69079
- 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));
69080
69208
  const sourceSignature = mapper ? instantiateSignature(contextualSignature, mapper) : contextualSignature;
69081
69209
  applyToParameterTypes(sourceSignature, signature, (source, target) => {
69082
- inferTypes(context.inferences, source, target);
69210
+ inferTypes(context, source, target);
69083
69211
  });
69084
69212
  if (!inferenceContext) {
69085
69213
  applyToReturnTypes(contextualSignature, signature, (source, target) => {
69086
- inferTypes(context.inferences, source, target, 128 /* ReturnType */);
69214
+ inferTypes(context, source, target, 128 /* ReturnType */);
69087
69215
  });
69088
69216
  }
69089
- return getSignatureInstantiation(signature, getInferredTypes(context), isInJSFile(contextualSignature.declaration));
69217
+ return getSignatureInstantiation(signature, getInferredTypes(context, returnFalse), isInJSFile(contextualSignature.declaration));
69090
69218
  }
69091
- function inferJsxTypeArguments(node, signature, checkMode, context) {
69219
+ function inferJsxTypeArguments(node, signature, checkMode, context, accept) {
69092
69220
  const paramType = getEffectiveFirstArgumentForJsxSignature(signature, node);
69093
69221
  const checkAttrType = checkExpressionWithContextualType(node.attributes, paramType, context, checkMode);
69094
- inferTypes(context.inferences, checkAttrType, paramType);
69095
- return getInferredTypes(context);
69222
+ inferTypes(context, checkAttrType, paramType);
69223
+ return getInferredTypes(context, accept);
69096
69224
  }
69097
69225
  function getThisArgumentType(thisArgumentNode) {
69098
69226
  if (!thisArgumentNode) {
@@ -69101,9 +69229,9 @@ function createTypeChecker(host) {
69101
69229
  const thisArgumentType = checkExpression(thisArgumentNode);
69102
69230
  return isOptionalChainRoot(thisArgumentNode.parent) ? getNonNullableType(thisArgumentType) : isOptionalChain(thisArgumentNode.parent) ? removeOptionalTypeMarker(thisArgumentType) : thisArgumentType;
69103
69231
  }
69104
- function inferTypeArguments(node, signature, args, checkMode, context) {
69232
+ function inferTypeArguments(node, signature, args, checkMode, context, accept) {
69105
69233
  if (isJsxOpeningLikeElement(node)) {
69106
- return inferJsxTypeArguments(node, signature, checkMode, context);
69234
+ return inferJsxTypeArguments(node, signature, checkMode, context, accept);
69107
69235
  }
69108
69236
  if (node.kind !== 167 /* Decorator */) {
69109
69237
  const skipBindingPatterns = every(signature.typeParameters, (p) => !!getDefaultFromTypeParameter(p));
@@ -69118,11 +69246,11 @@ function createTypeChecker(host) {
69118
69246
  const instantiatedType = instantiateType(contextualType, outerMapper);
69119
69247
  const contextualSignature = getSingleCallSignature(instantiatedType);
69120
69248
  const inferenceSourceType = contextualSignature && contextualSignature.typeParameters ? getOrCreateTypeFromSignature(getSignatureInstantiationWithoutFillingInTypeArguments(contextualSignature, contextualSignature.typeParameters)) : instantiatedType;
69121
- inferTypes(context.inferences, inferenceSourceType, inferenceTargetType, 128 /* ReturnType */);
69249
+ inferTypes(context, inferenceSourceType, inferenceTargetType, 128 /* ReturnType */);
69122
69250
  }
69123
69251
  const returnContext = createInferenceContext(signature.typeParameters, signature, context.flags);
69124
69252
  const returnSourceType = instantiateType(contextualType, outerContext && outerContext.returnMapper);
69125
- inferTypes(returnContext.inferences, returnSourceType, inferenceTargetType);
69253
+ inferTypes(returnContext, returnSourceType, inferenceTargetType);
69126
69254
  context.returnMapper = some(returnContext.inferences, hasInferenceCandidates) ? getMapperFromContext(cloneInferredPartOfContext(returnContext)) : void 0;
69127
69255
  }
69128
69256
  }
@@ -69138,7 +69266,7 @@ function createTypeChecker(host) {
69138
69266
  const thisType = getThisTypeOfSignature(signature);
69139
69267
  if (thisType && couldContainTypeVariables(thisType)) {
69140
69268
  const thisArgumentNode = getThisArgumentOfCall(node);
69141
- inferTypes(context.inferences, getThisArgumentType(thisArgumentNode), thisType);
69269
+ inferTypes(context, getThisArgumentType(thisArgumentNode), thisType);
69142
69270
  }
69143
69271
  for (let i = 0; i < argCount; i++) {
69144
69272
  const arg = args[i];
@@ -69146,15 +69274,15 @@ function createTypeChecker(host) {
69146
69274
  const paramType = getTypeAtPosition(signature, i);
69147
69275
  if (couldContainTypeVariables(paramType)) {
69148
69276
  const argType = checkExpressionWithContextualType(arg, paramType, context, checkMode);
69149
- inferTypes(context.inferences, argType, paramType);
69277
+ inferTypes(context, argType, paramType);
69150
69278
  }
69151
69279
  }
69152
69280
  }
69153
69281
  if (restType && couldContainTypeVariables(restType)) {
69154
69282
  const spreadType = getSpreadArgumentType(args, argCount, args.length, restType, context, checkMode);
69155
- inferTypes(context.inferences, spreadType, restType);
69283
+ inferTypes(context, spreadType, restType);
69156
69284
  }
69157
- return getInferredTypes(context);
69285
+ return getInferredTypes(context, accept);
69158
69286
  }
69159
69287
  function getMutableArrayOrTupleType(type) {
69160
69288
  return type.flags & 1048576 /* Union */ ? mapType(type, getMutableArrayOrTupleType) : type.flags & 1 /* Any */ || isMutableArrayOrTuple(getBaseConstraintOfType(type) || type) ? type : isTupleType(type) ? createTupleType(
@@ -69921,6 +70049,26 @@ function createTypeChecker(host) {
69921
70049
  }
69922
70050
  let checkCandidate;
69923
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
+ };
69924
70072
  if (candidate.typeParameters) {
69925
70073
  let typeArgumentTypes;
69926
70074
  if (some(typeArguments)) {
@@ -69941,7 +70089,7 @@ function createTypeChecker(host) {
69941
70089
  /*flags*/
69942
70090
  isInJSFile(node) ? 2 /* AnyDefault */ : 0 /* None */
69943
70091
  );
69944
- typeArgumentTypes = inferTypeArguments(node, candidate, args, argCheckMode | 8 /* SkipGenericFunctions */, inferenceContext);
70092
+ typeArgumentTypes = inferTypeArguments(node, candidate, args, argCheckMode | 8 /* SkipGenericFunctions */, inferenceContext, acceptor);
69945
70093
  argCheckMode |= inferenceContext.flags & 4 /* SkippedGenericFunction */ ? 8 /* SkipGenericFunctions */ : 0 /* Normal */;
69946
70094
  }
69947
70095
  checkCandidate = getSignatureInstantiation(candidate, typeArgumentTypes, isInJSFile(candidate.declaration), inferenceContext && inferenceContext.inferredTypeParameters);
@@ -69969,7 +70117,7 @@ function createTypeChecker(host) {
69969
70117
  if (argCheckMode) {
69970
70118
  argCheckMode = checkMode & 32 /* IsForStringLiteralArgumentCompletions */;
69971
70119
  if (inferenceContext) {
69972
- const typeArgumentTypes = inferTypeArguments(node, candidate, args, argCheckMode, inferenceContext);
70120
+ const typeArgumentTypes = inferTypeArguments(node, candidate, args, argCheckMode, inferenceContext, acceptor);
69973
70121
  checkCandidate = getSignatureInstantiation(candidate, typeArgumentTypes, isInJSFile(candidate.declaration), inferenceContext.inferredTypeParameters);
69974
70122
  if (getNonArrayRestType(candidate) && !hasCorrectArity(node, args, checkCandidate, signatureHelpTrailingComma2)) {
69975
70123
  candidateForArgumentArityError = checkCandidate;
@@ -70079,7 +70227,7 @@ function createTypeChecker(host) {
70079
70227
  /*flags*/
70080
70228
  isInJSFile(node) ? 2 /* AnyDefault */ : 0 /* None */
70081
70229
  );
70082
- 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);
70083
70231
  return createSignatureInstantiation(candidate, typeArgumentTypes);
70084
70232
  }
70085
70233
  function getLongestCandidateIndex(candidates, argsCount) {
@@ -71347,7 +71495,7 @@ function createTypeChecker(host) {
71347
71495
  if (declaration.type) {
71348
71496
  const typeNode = getEffectiveTypeAnnotationNode(declaration);
71349
71497
  if (typeNode) {
71350
- inferTypes(inferenceContext.inferences, getTypeFromTypeNode(typeNode), getTypeAtPosition(context, i));
71498
+ inferTypes(inferenceContext, getTypeFromTypeNode(typeNode), getTypeAtPosition(context, i));
71351
71499
  }
71352
71500
  }
71353
71501
  }
@@ -72059,7 +72207,7 @@ function createTypeChecker(host) {
72059
72207
  instantiatedContextualSignature = instantiateSignature(contextualSignature, inferenceContext.nonFixingMapper);
72060
72208
  }
72061
72209
  }
72062
- instantiatedContextualSignature || (instantiatedContextualSignature = inferenceContext ? instantiateSignature(contextualSignature, inferenceContext.mapper) : contextualSignature);
72210
+ instantiatedContextualSignature || (instantiatedContextualSignature = inferenceContext ? instantiateSignature(contextualSignature, getMapperFromContext(inferenceContext)) : contextualSignature);
72063
72211
  assignContextualParameterTypes(signature, instantiatedContextualSignature);
72064
72212
  } else {
72065
72213
  assignNonContextualParameterTypes(signature);
@@ -73440,7 +73588,7 @@ function createTypeChecker(host) {
73440
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);
73441
73589
  }
73442
73590
  function isConstTypeParameterContext(node) {
73443
- const contextualType = getContextualType(node, 0 /* None */);
73591
+ const contextualType = getContextualType(node, 1 /* Signature */);
73444
73592
  return !!contextualType && someType(contextualType, isConstTypeVariable);
73445
73593
  }
73446
73594
  function checkExpressionForMutableLocation(node, checkMode, forceTuple) {
@@ -73505,10 +73653,11 @@ function createTypeChecker(host) {
73505
73653
  if (returnSignature && !returnSignature.typeParameters && !every(context.inferences, hasInferenceCandidates)) {
73506
73654
  const uniqueTypeParameters = getUniqueTypeParameters(context, signature.typeParameters);
73507
73655
  const instantiatedSignature = getSignatureInstantiationWithoutFillingInTypeArguments(signature, uniqueTypeParameters);
73508
- const inferences = map(context.inferences, (info) => createInferenceInfo(info.typeParameter));
73656
+ const subcontext = cloneInferenceContext(context);
73657
+ subcontext.inferences = map(context.inferences, (info) => createInferenceInfo(info.typeParameter));
73509
73658
  applyToParameterTypes(instantiatedSignature, contextualSignature, (source, target) => {
73510
73659
  inferTypes(
73511
- inferences,
73660
+ subcontext,
73512
73661
  source,
73513
73662
  target,
73514
73663
  /*priority*/
@@ -73517,12 +73666,12 @@ function createTypeChecker(host) {
73517
73666
  true
73518
73667
  );
73519
73668
  });
73520
- if (some(inferences, hasInferenceCandidates)) {
73669
+ if (some(subcontext.inferences, hasInferenceCandidates)) {
73521
73670
  applyToReturnTypes(instantiatedSignature, contextualSignature, (source, target) => {
73522
- inferTypes(inferences, source, target);
73671
+ inferTypes(subcontext, source, target);
73523
73672
  });
73524
- if (!hasOverlappingInferences(context.inferences, inferences)) {
73525
- mergeInferences(context.inferences, inferences);
73673
+ if (!hasOverlappingInferences(context.inferences, subcontext.inferences)) {
73674
+ mergeInferenceContexts(context, subcontext);
73526
73675
  context.inferredTypeParameters = concatenate(context.inferredTypeParameters, uniqueTypeParameters);
73527
73676
  return getOrCreateTypeFromSignature(instantiatedSignature);
73528
73677
  }
@@ -73555,13 +73704,22 @@ function createTypeChecker(host) {
73555
73704
  }
73556
73705
  return false;
73557
73706
  }
73558
- function mergeInferences(target, source) {
73707
+ function mergeInferences(target, source, clone2 = false) {
73559
73708
  for (let i = 0; i < target.length; i++) {
73560
73709
  if (!hasInferenceCandidates(target[i]) && hasInferenceCandidates(source[i])) {
73561
- 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];
73562
73715
  }
73563
73716
  }
73564
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
+ }
73565
73723
  function getUniqueTypeParameters(context, typeParameters) {
73566
73724
  const result = [];
73567
73725
  let oldTypeParameters;