@typescript-deploys/pr-build 5.8.0-pr-61077-3 → 5.8.0-pr-60434-6

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
@@ -18,7 +18,7 @@ and limitations under the License.
18
18
 
19
19
  // src/compiler/corePublic.ts
20
20
  var versionMajorMinor = "5.8";
21
- var version = `${versionMajorMinor}.0-insiders.20250129`;
21
+ var version = `${versionMajorMinor}.0-insiders.20250212`;
22
22
 
23
23
  // src/compiler/core.ts
24
24
  var emptyArray = [];
@@ -3680,7 +3680,6 @@ var ObjectFlags = /* @__PURE__ */ ((ObjectFlags3) => {
3680
3680
  ObjectFlags3[ObjectFlags3["IsGenericObjectType"] = 4194304] = "IsGenericObjectType";
3681
3681
  ObjectFlags3[ObjectFlags3["IsGenericIndexType"] = 8388608] = "IsGenericIndexType";
3682
3682
  ObjectFlags3[ObjectFlags3["IsGenericType"] = 12582912] = "IsGenericType";
3683
- ObjectFlags3[ObjectFlags3["IsNarrowingType"] = 16777216] = "IsNarrowingType";
3684
3683
  ObjectFlags3[ObjectFlags3["ContainsIntersections"] = 16777216] = "ContainsIntersections";
3685
3684
  ObjectFlags3[ObjectFlags3["IsUnknownLikeUnionComputed"] = 33554432] = "IsUnknownLikeUnionComputed";
3686
3685
  ObjectFlags3[ObjectFlags3["IsUnknownLikeUnion"] = 67108864] = "IsUnknownLikeUnion";
@@ -41670,7 +41669,7 @@ function loadModuleFromSpecificNodeModulesDirectory(extensions, moduleName, node
41670
41669
  state2,
41671
41670
  packageInfo
41672
41671
  );
41673
- if (!pathAndExtension && packageInfo && (packageInfo.contents.packageJsonContent.exports === void 0 || packageInfo.contents.packageJsonContent.exports === null) && state2.features & 32 /* EsmMode */) {
41672
+ if (!pathAndExtension && !rest && packageInfo && (packageInfo.contents.packageJsonContent.exports === void 0 || packageInfo.contents.packageJsonContent.exports === null) && state2.features & 32 /* EsmMode */) {
41674
41673
  pathAndExtension = loadModuleFromFile(extensions2, combinePaths(candidate2, "index.js"), onlyRecordFailures, state2);
41675
41674
  }
41676
41675
  return withPackageId(packageInfo, pathAndExtension, state2);
@@ -46377,8 +46376,8 @@ function createTypeChecker(host) {
46377
46376
  writeSignature: (signature, enclosingDeclaration, flags, kind, writer) => {
46378
46377
  return signatureToString(signature, getParseTreeNode(enclosingDeclaration), flags, kind, writer);
46379
46378
  },
46380
- writeType: (type, enclosingDeclaration, flags, writer, verbosityLevel, out) => {
46381
- return typeToString(type, getParseTreeNode(enclosingDeclaration), flags, writer, verbosityLevel, out);
46379
+ writeType: (type, enclosingDeclaration, flags, writer) => {
46380
+ return typeToString(type, getParseTreeNode(enclosingDeclaration), flags, writer);
46382
46381
  },
46383
46382
  writeSymbol: (symbol, enclosingDeclaration, meaning, flags, writer) => {
46384
46383
  return symbolToString(symbol, getParseTreeNode(enclosingDeclaration), meaning, flags, writer);
@@ -47176,7 +47175,6 @@ function createTypeChecker(host) {
47176
47175
  [".jsx", ".jsx"],
47177
47176
  [".json", ".json"]
47178
47177
  ];
47179
- var narrowableReturnTypeCache = /* @__PURE__ */ new Map();
47180
47178
  initializeTypeChecker();
47181
47179
  return checker;
47182
47180
  function isDefinitelyReferenceToGlobalSymbolObject(node) {
@@ -50312,18 +50310,14 @@ function createTypeChecker(host) {
50312
50310
  return writer2;
50313
50311
  }
50314
50312
  }
50315
- function typeToString(type, enclosingDeclaration, flags = 1048576 /* AllowUniqueESSymbolType */ | 16384 /* UseAliasDefinedOutsideCurrentScope */, writer = createTextWriter(""), verbosityLevel, out) {
50316
- const noTruncation = compilerOptions.noErrorTruncation || flags & 1 /* NoTruncation */ || verbosityLevel !== void 0;
50313
+ function typeToString(type, enclosingDeclaration, flags = 1048576 /* AllowUniqueESSymbolType */ | 16384 /* UseAliasDefinedOutsideCurrentScope */, writer = createTextWriter("")) {
50314
+ const noTruncation = compilerOptions.noErrorTruncation || flags & 1 /* NoTruncation */;
50317
50315
  const typeNode = nodeBuilder.typeToTypeNode(
50318
50316
  type,
50319
50317
  enclosingDeclaration,
50320
- toNodeBuilderFlags(flags) | 70221824 /* IgnoreErrors */ | (noTruncation ? 1 /* NoTruncation */ : 0),
50318
+ toNodeBuilderFlags(flags) | 70221824 /* IgnoreErrors */ | (noTruncation ? 1 /* NoTruncation */ : 0 /* None */),
50321
50319
  /*internalFlags*/
50322
- void 0,
50323
- /*tracker*/
50324
- void 0,
50325
- verbosityLevel,
50326
- out
50320
+ void 0
50327
50321
  );
50328
50322
  if (typeNode === void 0) return Debug.fail("should always get typenode");
50329
50323
  const printer = type !== unresolvedType ? createPrinterWithRemoveComments() : createPrinterWithDefaults();
@@ -50550,127 +50544,31 @@ function createTypeChecker(host) {
50550
50544
  };
50551
50545
  return {
50552
50546
  syntacticBuilderResolver,
50553
- typeToTypeNode: (type, enclosingDeclaration, flags, internalFlags, tracker, verbosityLevel, out) => withContext(enclosingDeclaration, flags, internalFlags, tracker, verbosityLevel, (context) => typeToTypeNodeHelper(type, context), out),
50554
- typePredicateToTypePredicateNode: (typePredicate, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
50555
- enclosingDeclaration,
50556
- flags,
50557
- internalFlags,
50558
- tracker,
50559
- /*verbosityLevel*/
50560
- void 0,
50561
- (context) => typePredicateToTypePredicateNodeHelper(typePredicate, context)
50562
- ),
50563
- serializeTypeForDeclaration: (declaration, symbol, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
50564
- enclosingDeclaration,
50565
- flags,
50566
- internalFlags,
50567
- tracker,
50568
- /*verbosityLevel*/
50569
- void 0,
50570
- (context) => syntacticNodeBuilder.serializeTypeOfDeclaration(declaration, symbol, context)
50571
- ),
50572
- serializeReturnTypeForSignature: (signature, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
50573
- enclosingDeclaration,
50574
- flags,
50575
- internalFlags,
50576
- tracker,
50577
- /*verbosityLevel*/
50578
- void 0,
50579
- (context) => syntacticNodeBuilder.serializeReturnTypeForSignature(signature, getSymbolOfDeclaration(signature), context)
50580
- ),
50581
- serializeTypeForExpression: (expr, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
50582
- enclosingDeclaration,
50583
- flags,
50584
- internalFlags,
50585
- tracker,
50586
- /*verbosityLevel*/
50587
- void 0,
50588
- (context) => syntacticNodeBuilder.serializeTypeOfExpression(expr, context)
50589
- ),
50590
- indexInfoToIndexSignatureDeclaration: (indexInfo, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
50591
- enclosingDeclaration,
50592
- flags,
50593
- internalFlags,
50594
- tracker,
50595
- /*verbosityLevel*/
50596
- void 0,
50597
- (context) => indexInfoToIndexSignatureDeclarationHelper(
50598
- indexInfo,
50599
- context,
50600
- /*typeNode*/
50601
- void 0
50602
- )
50603
- ),
50604
- signatureToSignatureDeclaration: (signature, kind, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
50605
- enclosingDeclaration,
50606
- flags,
50607
- internalFlags,
50608
- tracker,
50609
- /*verbosityLevel*/
50610
- void 0,
50611
- (context) => signatureToSignatureDeclarationHelper(signature, kind, context)
50612
- ),
50613
- symbolToEntityName: (symbol, meaning, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
50614
- enclosingDeclaration,
50615
- flags,
50616
- internalFlags,
50617
- tracker,
50618
- /*verbosityLevel*/
50619
- void 0,
50620
- (context) => symbolToName(
50621
- symbol,
50622
- context,
50623
- meaning,
50624
- /*expectsIdentifier*/
50625
- false
50626
- )
50627
- ),
50628
- symbolToExpression: (symbol, meaning, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
50629
- enclosingDeclaration,
50630
- flags,
50631
- internalFlags,
50632
- tracker,
50633
- /*verbosityLevel*/
50634
- void 0,
50635
- (context) => symbolToExpression(symbol, context, meaning)
50636
- ),
50637
- symbolToTypeParameterDeclarations: (symbol, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
50638
- enclosingDeclaration,
50639
- flags,
50640
- internalFlags,
50641
- tracker,
50642
- /*verbosityLevel*/
50643
- void 0,
50644
- (context) => typeParametersToTypeParameterDeclarations(symbol, context)
50645
- ),
50646
- symbolToParameterDeclaration: (symbol, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
50647
- enclosingDeclaration,
50648
- flags,
50649
- internalFlags,
50650
- tracker,
50651
- /*verbosityLevel*/
50652
- void 0,
50653
- (context) => symbolToParameterDeclaration(symbol, context)
50654
- ),
50655
- typeParameterToDeclaration: (parameter, enclosingDeclaration, flags, internalFlags, tracker, verbosityLevel) => withContext(enclosingDeclaration, flags, internalFlags, tracker, verbosityLevel, (context) => typeParameterToDeclaration(parameter, context)),
50656
- symbolTableToDeclarationStatements: (symbolTable, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
50657
- enclosingDeclaration,
50658
- flags,
50659
- internalFlags,
50660
- tracker,
50661
- /*verbosityLevel*/
50662
- void 0,
50663
- (context) => symbolTableToDeclarationStatements(symbolTable, context)
50664
- ),
50665
- symbolToNode: (symbol, meaning, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
50666
- enclosingDeclaration,
50667
- flags,
50668
- internalFlags,
50669
- tracker,
50670
- /*verbosityLevel*/
50671
- void 0,
50672
- (context) => symbolToNode(symbol, context, meaning)
50673
- )
50547
+ typeToTypeNode: (type, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => typeToTypeNodeHelper(type, context)),
50548
+ typePredicateToTypePredicateNode: (typePredicate, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => typePredicateToTypePredicateNodeHelper(typePredicate, context)),
50549
+ serializeTypeForExpression: (expr, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => syntacticNodeBuilder.serializeTypeOfExpression(expr, context)),
50550
+ serializeTypeForDeclaration: (declaration, symbol, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => syntacticNodeBuilder.serializeTypeOfDeclaration(declaration, symbol, context)),
50551
+ serializeReturnTypeForSignature: (signature, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => syntacticNodeBuilder.serializeReturnTypeForSignature(signature, getSymbolOfDeclaration(signature), context)),
50552
+ indexInfoToIndexSignatureDeclaration: (indexInfo, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => indexInfoToIndexSignatureDeclarationHelper(
50553
+ indexInfo,
50554
+ context,
50555
+ /*typeNode*/
50556
+ void 0
50557
+ )),
50558
+ signatureToSignatureDeclaration: (signature, kind, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => signatureToSignatureDeclarationHelper(signature, kind, context)),
50559
+ symbolToEntityName: (symbol, meaning, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => symbolToName(
50560
+ symbol,
50561
+ context,
50562
+ meaning,
50563
+ /*expectsIdentifier*/
50564
+ false
50565
+ )),
50566
+ symbolToExpression: (symbol, meaning, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => symbolToExpression(symbol, context, meaning)),
50567
+ symbolToTypeParameterDeclarations: (symbol, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => typeParametersToTypeParameterDeclarations(symbol, context)),
50568
+ symbolToParameterDeclaration: (symbol, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => symbolToParameterDeclaration(symbol, context)),
50569
+ typeParameterToDeclaration: (parameter, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => typeParameterToDeclaration(parameter, context)),
50570
+ symbolTableToDeclarationStatements: (symbolTable, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => symbolTableToDeclarationStatements(symbolTable, context)),
50571
+ symbolToNode: (symbol, meaning, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => symbolToNode(symbol, context, meaning))
50674
50572
  };
50675
50573
  function getTypeFromTypeNode2(context, node, noMappedTypes) {
50676
50574
  const type = getTypeFromTypeNodeWithoutContext(node);
@@ -50712,7 +50610,7 @@ function createTypeChecker(host) {
50712
50610
  }
50713
50611
  return symbolToExpression(symbol, context, meaning);
50714
50612
  }
50715
- function withContext(enclosingDeclaration, flags, internalFlags, tracker, verbosityLevel, cb, out) {
50613
+ function withContext(enclosingDeclaration, flags, internalFlags, tracker, cb) {
50716
50614
  const moduleResolverHost = (tracker == null ? void 0 : tracker.trackSymbol) ? tracker.moduleResolverHost : (internalFlags || 0 /* None */) & 4 /* DoNotIncludeSymbolChain */ ? createBasicNodeBuilderModuleSpecifierResolutionHost(host) : void 0;
50717
50615
  const context = {
50718
50616
  enclosingDeclaration,
@@ -50720,7 +50618,6 @@ function createTypeChecker(host) {
50720
50618
  flags: flags || 0 /* None */,
50721
50619
  internalFlags: internalFlags || 0 /* None */,
50722
50620
  tracker: void 0,
50723
- unfoldDepth: verbosityLevel ?? -1,
50724
50621
  encounteredError: false,
50725
50622
  suppressReportInferenceFallback: false,
50726
50623
  reportedDiagnostic: false,
@@ -50742,18 +50639,13 @@ function createTypeChecker(host) {
50742
50639
  typeParameterNamesByText: void 0,
50743
50640
  typeParameterNamesByTextNextNameCount: void 0,
50744
50641
  enclosingSymbolTypes: /* @__PURE__ */ new Map(),
50745
- mapper: void 0,
50746
- depth: 0,
50747
- couldUnfoldMore: false
50642
+ mapper: void 0
50748
50643
  };
50749
50644
  context.tracker = new SymbolTrackerImpl(context, tracker, moduleResolverHost);
50750
50645
  const resultingNode = cb(context);
50751
50646
  if (context.truncating && context.flags & 1 /* NoTruncation */) {
50752
50647
  context.tracker.reportTruncationError();
50753
50648
  }
50754
- if (out) {
50755
- out.couldUnfoldMore = context.couldUnfoldMore;
50756
- }
50757
50649
  return context.encounteredError ? void 0 : resultingNode;
50758
50650
  }
50759
50651
  function addSymbolTypeToContext(context, symbol, type) {
@@ -50772,36 +50664,16 @@ function createTypeChecker(host) {
50772
50664
  function saveRestoreFlags(context) {
50773
50665
  const flags = context.flags;
50774
50666
  const internalFlags = context.internalFlags;
50775
- const depth = context.depth;
50776
50667
  return restore;
50777
50668
  function restore() {
50778
50669
  context.flags = flags;
50779
50670
  context.internalFlags = internalFlags;
50780
- context.depth = depth;
50781
50671
  }
50782
50672
  }
50783
50673
  function checkTruncationLength(context) {
50784
50674
  if (context.truncating) return context.truncating;
50785
50675
  return context.truncating = context.approximateLength > (context.flags & 1 /* NoTruncation */ ? noTruncationMaximumTruncationLength : defaultMaximumTruncationLength);
50786
50676
  }
50787
- function couldUnfoldType(type, context) {
50788
- var _a;
50789
- if ((_a = context.visitedTypes) == null ? void 0 : _a.has(type.id)) {
50790
- return false;
50791
- }
50792
- return context.depth < context.unfoldDepth || context.depth === context.unfoldDepth && !context.couldUnfoldMore;
50793
- }
50794
- function canUnfoldType(type, context) {
50795
- var _a;
50796
- if ((_a = context.visitedTypes) == null ? void 0 : _a.has(type.id)) {
50797
- return false;
50798
- }
50799
- const result = context.depth < context.unfoldDepth;
50800
- if (!result) {
50801
- context.couldUnfoldMore = true;
50802
- }
50803
- return result;
50804
- }
50805
50677
  function typeToTypeNodeHelper(type, context) {
50806
50678
  const restoreFlags = saveRestoreFlags(context);
50807
50679
  const typeNode = typeToTypeNodeWorker(type, context);
@@ -50949,27 +50821,16 @@ function createTypeChecker(host) {
50949
50821
  return factory.createThisTypeNode();
50950
50822
  }
50951
50823
  if (!inTypeAlias && type.aliasSymbol && (context.flags & 16384 /* UseAliasDefinedOutsideCurrentScope */ || isTypeSymbolAccessible(type.aliasSymbol, context.enclosingDeclaration))) {
50952
- if (!canUnfoldType(type, context)) {
50953
- const typeArgumentNodes = mapToTypeNodes(type.aliasTypeArguments, context);
50954
- if (isReservedMemberName(type.aliasSymbol.escapedName) && !(type.aliasSymbol.flags & 32 /* Class */)) return factory.createTypeReferenceNode(factory.createIdentifier(""), typeArgumentNodes);
50955
- if (length(typeArgumentNodes) === 1 && type.aliasSymbol === globalArrayType.symbol) {
50956
- return factory.createArrayTypeNode(typeArgumentNodes[0]);
50957
- }
50958
- return symbolToTypeNode(type.aliasSymbol, context, 788968 /* Type */, typeArgumentNodes);
50824
+ const typeArgumentNodes = mapToTypeNodes(type.aliasTypeArguments, context);
50825
+ if (isReservedMemberName(type.aliasSymbol.escapedName) && !(type.aliasSymbol.flags & 32 /* Class */)) return factory.createTypeReferenceNode(factory.createIdentifier(""), typeArgumentNodes);
50826
+ if (length(typeArgumentNodes) === 1 && type.aliasSymbol === globalArrayType.symbol) {
50827
+ return factory.createArrayTypeNode(typeArgumentNodes[0]);
50959
50828
  }
50960
- context.depth += 1;
50829
+ return symbolToTypeNode(type.aliasSymbol, context, 788968 /* Type */, typeArgumentNodes);
50961
50830
  }
50962
50831
  const objectFlags = getObjectFlags(type);
50963
50832
  if (objectFlags & 4 /* Reference */) {
50964
50833
  Debug.assert(!!(type.flags & 524288 /* Object */));
50965
- if (canUnfoldType(type, context)) {
50966
- context.depth += 1;
50967
- return createAnonymousTypeNode(
50968
- type,
50969
- /*forceClassExpansion*/
50970
- true
50971
- );
50972
- }
50973
50834
  return type.node ? visitAndTransformType(type, typeReferenceToTypeNode) : typeReferenceToTypeNode(type);
50974
50835
  }
50975
50836
  if (type.flags & 262144 /* TypeParameter */ || objectFlags & 3 /* ClassOrInterface */) {
@@ -50999,14 +50860,6 @@ function createTypeChecker(host) {
50999
50860
  void 0
51000
50861
  );
51001
50862
  }
51002
- if (objectFlags & 3 /* ClassOrInterface */ && canUnfoldType(type, context)) {
51003
- context.depth += 1;
51004
- return createAnonymousTypeNode(
51005
- type,
51006
- /*forceClassExpansion*/
51007
- true
51008
- );
51009
- }
51010
50863
  if (type.symbol) {
51011
50864
  return symbolToTypeNode(type.symbol, context, 788968 /* Type */);
51012
50865
  }
@@ -51210,7 +51063,7 @@ function createTypeChecker(host) {
51210
51063
  }
51211
51064
  return result;
51212
51065
  }
51213
- function createAnonymousTypeNode(type2, forceClassExpansion = false) {
51066
+ function createAnonymousTypeNode(type2) {
51214
51067
  var _a2, _b2;
51215
51068
  const typeId = type2.id;
51216
51069
  const symbol = type2.symbol;
@@ -51233,7 +51086,7 @@ function createTypeChecker(host) {
51233
51086
  const isInstanceType = isClassInstanceSide(type2) ? 788968 /* Type */ : 111551 /* Value */;
51234
51087
  if (isJSConstructor(symbol.valueDeclaration)) {
51235
51088
  return symbolToTypeNode(symbol, context, isInstanceType);
51236
- } else if (symbol.flags & 32 /* Class */ && !forceClassExpansion && !getBaseTypeVariableOfClass(symbol) && !(symbol.valueDeclaration && isClassLike(symbol.valueDeclaration) && context.flags & 2048 /* WriteClassExpressionAsTypeLiteral */ && (!isClassDeclaration(symbol.valueDeclaration) || isSymbolAccessible(
51089
+ } else if (symbol.flags & 32 /* Class */ && !getBaseTypeVariableOfClass(symbol) && !(symbol.valueDeclaration && isClassLike(symbol.valueDeclaration) && context.flags & 2048 /* WriteClassExpressionAsTypeLiteral */ && (!isClassDeclaration(symbol.valueDeclaration) || isSymbolAccessible(
51237
51090
  symbol,
51238
51091
  context.enclosingDeclaration,
51239
51092
  isInstanceType,
@@ -51277,7 +51130,7 @@ function createTypeChecker(host) {
51277
51130
  if (id && !context.symbolDepth) {
51278
51131
  context.symbolDepth = /* @__PURE__ */ new Map();
51279
51132
  }
51280
- const links = context.unfoldDepth >= 0 ? void 0 : context.enclosingDeclaration && getNodeLinks(context.enclosingDeclaration);
51133
+ const links = context.enclosingDeclaration && getNodeLinks(context.enclosingDeclaration);
51281
51134
  const key = `${getTypeId(type2)}|${context.flags}|${context.internalFlags}`;
51282
51135
  if (links) {
51283
51136
  links.serializedTypes || (links.serializedTypes = /* @__PURE__ */ new Map());
@@ -52224,7 +52077,7 @@ function createTypeChecker(host) {
52224
52077
  return factory.createTypeParameterDeclaration(modifiers, name, constraintNode, defaultParameterNode);
52225
52078
  }
52226
52079
  function typeToTypeNodeHelperWithPossibleReusableTypeNode(type, typeNode, context) {
52227
- return !couldUnfoldType(type, context) && typeNode && getTypeFromTypeNode2(context, typeNode) === type && syntacticNodeBuilder.tryReuseExistingTypeNode(context, typeNode) || typeToTypeNodeHelper(type, context);
52080
+ return typeNode && getTypeFromTypeNode2(context, typeNode) === type && syntacticNodeBuilder.tryReuseExistingTypeNode(context, typeNode) || typeToTypeNodeHelper(type, context);
52228
52081
  }
52229
52082
  function typeParameterToDeclaration(type, context, constraint = getConstraintOfTypeParameter(type)) {
52230
52083
  const constraintNode = constraint && typeToTypeNodeHelperWithPossibleReusableTypeNode(constraint, getConstraintDeclaration(type), context);
@@ -52871,7 +52724,7 @@ function createTypeChecker(host) {
52871
52724
  let result;
52872
52725
  const addUndefinedForParameter = declaration && (isParameter(declaration) || isJSDocParameterTag(declaration)) && requiresAddingImplicitUndefined(declaration, context.enclosingDeclaration);
52873
52726
  const decl = declaration ?? symbol.valueDeclaration ?? getDeclarationWithTypeAnnotation(symbol) ?? ((_a = symbol.declarations) == null ? void 0 : _a[0]);
52874
- if (!couldUnfoldType(type, context) && decl) {
52727
+ if (decl) {
52875
52728
  if (isAccessor(decl)) {
52876
52729
  result = syntacticNodeBuilder.serializeTypeOfAccessor(decl, symbol, context);
52877
52730
  } else if (hasInferredType(decl) && !nodeIsSynthesized(decl) && !(getObjectFlags(type) & 196608 /* RequiresWidening */)) {
@@ -59583,14 +59436,11 @@ function createTypeChecker(host) {
59583
59436
  function isNoInferType(type) {
59584
59437
  return !!(type.flags & 33554432 /* Substitution */ && type.constraint.flags & 2 /* Unknown */);
59585
59438
  }
59586
- function isNarrowingSubstitutionType(type) {
59587
- return !!(type.flags & 33554432 /* Substitution */ && type.objectFlags & 16777216 /* IsNarrowingType */);
59439
+ function getSubstitutionType(baseType, constraint) {
59440
+ return constraint.flags & 3 /* AnyOrUnknown */ || constraint === baseType || baseType.flags & 1 /* Any */ ? baseType : getOrCreateSubstitutionType(baseType, constraint);
59588
59441
  }
59589
- function getSubstitutionType(baseType, constraint, isNarrowed) {
59590
- return constraint.flags & 3 /* AnyOrUnknown */ || constraint === baseType || baseType.flags & 1 /* Any */ ? baseType : getOrCreateSubstitutionType(baseType, constraint, isNarrowed);
59591
- }
59592
- function getOrCreateSubstitutionType(baseType, constraint, isNarrowed) {
59593
- const id = `${getTypeId(baseType)}>${getTypeId(constraint)}${isNarrowed ? ">N" : ""}`;
59442
+ function getOrCreateSubstitutionType(baseType, constraint) {
59443
+ const id = `${getTypeId(baseType)}>${getTypeId(constraint)}`;
59594
59444
  const cached = substitutionTypes.get(id);
59595
59445
  if (cached) {
59596
59446
  return cached;
@@ -59598,9 +59448,6 @@ function createTypeChecker(host) {
59598
59448
  const result = createType(33554432 /* Substitution */);
59599
59449
  result.baseType = baseType;
59600
59450
  result.constraint = constraint;
59601
- if (isNarrowed) {
59602
- result.objectFlags |= 16777216 /* IsNarrowingType */;
59603
- }
59604
59451
  substitutionTypes.set(id, result);
59605
59452
  return result;
59606
59453
  }
@@ -61806,7 +61653,7 @@ function createTypeChecker(host) {
61806
61653
  function isDeferredType(type, checkTuples) {
61807
61654
  return isGenericType(type) || checkTuples && isTupleType(type) && some(getElementTypes(type), isGenericType);
61808
61655
  }
61809
- function getConditionalType(root, mapper, forConstraint, aliasSymbol, aliasTypeArguments, forNarrowing) {
61656
+ function getConditionalType(root, mapper, forConstraint, aliasSymbol, aliasTypeArguments) {
61810
61657
  let result;
61811
61658
  let extraTypes;
61812
61659
  let tailCount = 0;
@@ -61823,11 +61670,10 @@ function createTypeChecker(host) {
61823
61670
  if (checkType === wildcardType || extendsType === wildcardType) {
61824
61671
  return wildcardType;
61825
61672
  }
61826
- const effectiveCheckType = forNarrowing && isNarrowingSubstitutionType(checkType) ? checkType.constraint : checkType;
61827
61673
  const checkTypeNode = skipTypeParentheses(root.node.checkType);
61828
61674
  const extendsTypeNode = skipTypeParentheses(root.node.extendsType);
61829
61675
  const checkTuples = isSimpleTupleType(checkTypeNode) && isSimpleTupleType(extendsTypeNode) && length(checkTypeNode.elements) === length(extendsTypeNode.elements);
61830
- const checkTypeDeferred = isDeferredType(effectiveCheckType, checkTuples);
61676
+ const checkTypeDeferred = isDeferredType(checkType, checkTuples);
61831
61677
  let combinedMapper;
61832
61678
  if (root.inferTypeParameters) {
61833
61679
  const context = createInferenceContext(
@@ -61846,8 +61692,8 @@ function createTypeChecker(host) {
61846
61692
  }
61847
61693
  const inferredExtendsType = combinedMapper ? instantiateType(root.extendsType, combinedMapper) : extendsType;
61848
61694
  if (!checkTypeDeferred && !isDeferredType(inferredExtendsType, checkTuples)) {
61849
- if (!(inferredExtendsType.flags & 3 /* AnyOrUnknown */) && (effectiveCheckType.flags & 1 /* Any */ || !isTypeAssignableTo(getPermissiveInstantiation(effectiveCheckType), getPermissiveInstantiation(inferredExtendsType)))) {
61850
- if (effectiveCheckType.flags & 1 /* Any */ || forConstraint && !(inferredExtendsType.flags & 131072 /* Never */) && someType(getPermissiveInstantiation(inferredExtendsType), (t) => isTypeAssignableTo(t, getPermissiveInstantiation(effectiveCheckType)))) {
61695
+ if (!(inferredExtendsType.flags & 3 /* AnyOrUnknown */) && (checkType.flags & 1 /* Any */ || !isTypeAssignableTo(getPermissiveInstantiation(checkType), getPermissiveInstantiation(inferredExtendsType)))) {
61696
+ if (checkType.flags & 1 /* Any */ || forConstraint && !(inferredExtendsType.flags & 131072 /* Never */) && someType(getPermissiveInstantiation(inferredExtendsType), (t) => isTypeAssignableTo(t, getPermissiveInstantiation(checkType)))) {
61851
61697
  (extraTypes || (extraTypes = [])).push(instantiateType(getTypeFromTypeNode(root.node.trueType), combinedMapper || mapper));
61852
61698
  }
61853
61699
  const falseType2 = getTypeFromTypeNode(root.node.falseType);
@@ -61864,7 +61710,7 @@ function createTypeChecker(host) {
61864
61710
  result = instantiateType(falseType2, mapper);
61865
61711
  break;
61866
61712
  }
61867
- if (inferredExtendsType.flags & 3 /* AnyOrUnknown */ || isTypeAssignableTo(getRestrictiveInstantiation(effectiveCheckType), getRestrictiveInstantiation(inferredExtendsType))) {
61713
+ if (inferredExtendsType.flags & 3 /* AnyOrUnknown */ || isTypeAssignableTo(getRestrictiveInstantiation(checkType), getRestrictiveInstantiation(inferredExtendsType))) {
61868
61714
  const trueType2 = getTypeFromTypeNode(root.node.trueType);
61869
61715
  const trueMapper = combinedMapper || mapper;
61870
61716
  if (canTailRecurse(trueType2, trueMapper)) {
@@ -62830,42 +62676,8 @@ function createTypeChecker(host) {
62830
62676
  if (!result) {
62831
62677
  const newMapper = createTypeMapper(root.outerTypeParameters, typeArguments);
62832
62678
  const checkType = root.checkType;
62833
- let distributionType = root.isDistributive ? getReducedType(getMappedType(checkType, newMapper)) : void 0;
62834
- if (distributionType && isNoInferType(distributionType)) {
62835
- distributionType = distributionType.baseType;
62836
- }
62837
- let narrowingBaseType;
62838
- const forNarrowing = distributionType && isNarrowingSubstitutionType(distributionType) && isNarrowableConditionalType(type, mapper);
62839
- if (forNarrowing) {
62840
- narrowingBaseType = distributionType.baseType;
62841
- distributionType = getReducedType(distributionType.constraint);
62842
- }
62843
- if (distributionType && checkType !== distributionType && distributionType.flags & (1048576 /* Union */ | 131072 /* Never */)) {
62844
- if (narrowingBaseType) {
62845
- result = mapTypeToIntersection(
62846
- distributionType,
62847
- (t) => getConditionalType(
62848
- root,
62849
- prependTypeMapping(checkType, getSubstitutionType(
62850
- narrowingBaseType,
62851
- t,
62852
- /*isNarrowed*/
62853
- true
62854
- ), newMapper),
62855
- forConstraint,
62856
- /*aliasSymbol*/
62857
- void 0,
62858
- /*aliasTypeArguments*/
62859
- void 0,
62860
- forNarrowing
62861
- )
62862
- );
62863
- } else {
62864
- result = mapTypeWithAlias(distributionType, (t) => getConditionalType(root, prependTypeMapping(checkType, t, newMapper), forConstraint), aliasSymbol, aliasTypeArguments);
62865
- }
62866
- } else {
62867
- result = getConditionalType(root, newMapper, forConstraint, aliasSymbol, aliasTypeArguments, forNarrowing);
62868
- }
62679
+ const distributionType = root.isDistributive ? getReducedType(getMappedType(checkType, newMapper)) : void 0;
62680
+ result = distributionType && checkType !== distributionType && distributionType.flags & (1048576 /* Union */ | 131072 /* Never */) ? mapTypeWithAlias(distributionType, (t) => getConditionalType(root, prependTypeMapping(checkType, t, newMapper), forConstraint), aliasSymbol, aliasTypeArguments) : getConditionalType(root, newMapper, forConstraint, aliasSymbol, aliasTypeArguments);
62869
62681
  root.instantiations.set(id, result);
62870
62682
  }
62871
62683
  return result;
@@ -64008,12 +63820,10 @@ function createTypeChecker(host) {
64008
63820
  function shouldNormalizeIntersection(type) {
64009
63821
  let hasInstantiable = false;
64010
63822
  let hasNullableOrEmpty = false;
64011
- let hasSubstitution = false;
64012
63823
  for (const t of type.types) {
64013
63824
  hasInstantiable || (hasInstantiable = !!(t.flags & 465829888 /* Instantiable */));
64014
63825
  hasNullableOrEmpty || (hasNullableOrEmpty = !!(t.flags & 98304 /* Nullable */) || isEmptyAnonymousObjectType(t));
64015
- hasSubstitution || (hasSubstitution = isNarrowingSubstitutionType(t));
64016
- if (hasInstantiable && hasNullableOrEmpty || hasSubstitution) return true;
63826
+ if (hasInstantiable && hasNullableOrEmpty) return true;
64017
63827
  }
64018
63828
  return false;
64019
63829
  }
@@ -69173,18 +68983,6 @@ function createTypeChecker(host) {
69173
68983
  }
69174
68984
  return changed ? mappedTypes && getUnionType(mappedTypes, noReductions ? 0 /* None */ : 1 /* Literal */) : type;
69175
68985
  }
69176
- function mapTypeToIntersection(type, mapper) {
69177
- if (type.flags & 131072 /* Never */) {
69178
- return type;
69179
- }
69180
- if (!(type.flags & 1048576 /* Union */)) {
69181
- return mapper(type);
69182
- }
69183
- const origin = type.origin;
69184
- const types = origin && origin.flags & 1048576 /* Union */ ? origin.types : type.types;
69185
- const mappedTypes = types.map((t) => t.flags & 1048576 /* Union */ ? mapTypeToIntersection(t, mapper) : mapper(t));
69186
- return getIntersectionType(mappedTypes);
69187
- }
69188
68986
  function mapTypeWithAlias(type, mapper, aliasSymbol, aliasTypeArguments) {
69189
68987
  return type.flags & 1048576 /* Union */ && aliasSymbol ? getUnionType(map(type.types, mapper), 1 /* Literal */, aliasSymbol, aliasTypeArguments) : mapType(type, mapper);
69190
68988
  }
@@ -70769,11 +70567,11 @@ function createTypeChecker(host) {
70769
70567
  ));
70770
70568
  return contextualType && !isGenericType(contextualType);
70771
70569
  }
70772
- function getNarrowableTypeForReference(type, reference, checkMode, forReturnTypeNarrowing) {
70570
+ function getNarrowableTypeForReference(type, reference, checkMode) {
70773
70571
  if (isNoInferType(type)) {
70774
70572
  type = type.baseType;
70775
70573
  }
70776
- const substituteConstraints = !(checkMode && checkMode & 2 /* Inferential */) && someType(type, isGenericTypeWithUnionConstraint) && (forReturnTypeNarrowing || isConstraintPosition(type, reference) || hasContextualTypeWithNoGenericTypes(reference, checkMode));
70574
+ const substituteConstraints = !(checkMode && checkMode & 2 /* Inferential */) && someType(type, isGenericTypeWithUnionConstraint) && (isConstraintPosition(type, reference) || hasContextualTypeWithNoGenericTypes(reference, checkMode));
70777
70575
  return substituteConstraints ? mapType(type, getBaseConstraintOrType) : type;
70778
70576
  }
70779
70577
  function isExportOrExportExpression(location) {
@@ -71900,16 +71698,9 @@ function createTypeChecker(host) {
71900
71698
  function getContextualTypeForReturnExpression(node, contextFlags) {
71901
71699
  const func = getContainingFunction(node);
71902
71700
  if (func) {
71903
- const functionFlags = getFunctionFlags(func);
71904
- const links = getNodeLinks(node);
71905
- if (links.contextualReturnType) {
71906
- if (functionFlags & 2 /* Async */) {
71907
- return getUnionType([links.contextualReturnType, createPromiseLikeType(links.contextualReturnType)]);
71908
- }
71909
- return links.contextualReturnType;
71910
- }
71911
71701
  let contextualReturnType = getContextualReturnType(func, contextFlags);
71912
71702
  if (contextualReturnType) {
71703
+ const functionFlags = getFunctionFlags(func);
71913
71704
  if (functionFlags & 1 /* Generator */) {
71914
71705
  const isAsyncGenerator = (functionFlags & 2 /* Async */) !== 0;
71915
71706
  if (contextualReturnType.flags & 1048576 /* Union */) {
@@ -72552,6 +72343,50 @@ function createTypeChecker(host) {
72552
72343
  )
72553
72344
  );
72554
72345
  }
72346
+ function discriminateContextualTypeByArrayElements(node, contextualType) {
72347
+ const key = `D${getNodeId(node)},${getTypeId(contextualType)}`;
72348
+ const cachedType = getCachedType(key);
72349
+ if (cachedType) return cachedType;
72350
+ const isIndexPropertyLike = (property) => /^[-+]?\d+$/.test(property.escapedName);
72351
+ const hasIndexPropertyOutOfRange = (type, length2) => some(getPropertiesOfType(type), (p) => {
72352
+ if (p.flags & 16777216 /* Optional */ || !isIndexPropertyLike(p)) return false;
72353
+ const index = +p.escapedName;
72354
+ return index < 0 || index >= length2;
72355
+ });
72356
+ const hasIndexPropertyInRange = (type, length2) => some(getPropertiesOfType(type), (p) => {
72357
+ if (!isIndexPropertyLike(p)) return false;
72358
+ const index = +p.escapedName;
72359
+ return index >= 0 || index < length2;
72360
+ });
72361
+ const elementsLength = node.elements.length;
72362
+ const filteredType = filterType(contextualType, (type) => {
72363
+ if (isTupleType(type)) {
72364
+ return elementsLength >= type.target.minLength && (!!(type.target.combinedFlags & 12 /* Variable */) || elementsLength <= type.target.fixedLength);
72365
+ }
72366
+ return !hasIndexPropertyOutOfRange(type, elementsLength);
72367
+ });
72368
+ if (filteredType.flags & 131072 /* Never */) return setCachedType(key, contextualType);
72369
+ if (!(filteredType.flags & 1048576 /* Union */)) {
72370
+ return setCachedType(
72371
+ key,
72372
+ isTupleType(filteredType) || hasIndexPropertyInRange(filteredType, elementsLength) ? filteredType : contextualType
72373
+ );
72374
+ }
72375
+ return setCachedType(
72376
+ key,
72377
+ discriminateTypeByDiscriminableItems(
72378
+ filteredType,
72379
+ filter(
72380
+ map(node.elements, (element, index) => {
72381
+ const name = "" + index;
72382
+ return isPossiblyDiscriminantValue(element) && isDiscriminantProperty(filteredType, name) ? [() => getContextFreeTypeOfExpression(element), name] : void 0;
72383
+ }),
72384
+ (discriminator) => !!discriminator
72385
+ ),
72386
+ isTypeAssignableTo
72387
+ )
72388
+ );
72389
+ }
72555
72390
  function getApparentTypeOfContextualType(node, contextFlags) {
72556
72391
  const contextualType = isObjectLiteralMethod(node) ? getContextualTypeForObjectLiteralMethod(node, contextFlags) : getContextualType(node, contextFlags);
72557
72392
  const instantiatedType = instantiateContextualType(contextualType, node, contextFlags);
@@ -72566,7 +72401,12 @@ function createTypeChecker(host) {
72566
72401
  /*noReductions*/
72567
72402
  true
72568
72403
  );
72569
- return apparentType.flags & 1048576 /* Union */ && isObjectLiteralExpression(node) ? discriminateContextualTypeByObjectMembers(node, apparentType) : apparentType.flags & 1048576 /* Union */ && isJsxAttributes(node) ? discriminateContextualTypeByJSXAttributes(node, apparentType) : apparentType;
72404
+ if (apparentType.flags & 1048576 /* Union */) {
72405
+ if (isObjectLiteralExpression(node)) return discriminateContextualTypeByObjectMembers(node, apparentType);
72406
+ if (isJsxAttributes(node)) return discriminateContextualTypeByJSXAttributes(node, apparentType);
72407
+ if (isArrayLiteralExpression(node)) return discriminateContextualTypeByArrayElements(node, apparentType);
72408
+ }
72409
+ return apparentType;
72570
72410
  }
72571
72411
  }
72572
72412
  function instantiateContextualType(contextualType, node, contextFlags) {
@@ -72607,13 +72447,6 @@ function createTypeChecker(host) {
72607
72447
  if (index >= 0) {
72608
72448
  return contextualTypes[index];
72609
72449
  }
72610
- const links = getNodeLinks(node);
72611
- if (links.contextualReturnType) {
72612
- if (node.flags & 65536 /* AwaitContext */) {
72613
- return getUnionType([links.contextualReturnType, createPromiseLikeType(links.contextualReturnType)]);
72614
- }
72615
- return links.contextualReturnType;
72616
- }
72617
72450
  const { parent } = node;
72618
72451
  switch (parent.kind) {
72619
72452
  case 260 /* VariableDeclaration */:
@@ -83602,199 +83435,7 @@ function createTypeChecker(host) {
83602
83435
  ) : exprType;
83603
83436
  const effectiveExpr = expr && getEffectiveCheckNode(expr);
83604
83437
  const errorNode = inReturnStatement && !inConditionalExpression ? node : effectiveExpr;
83605
- if (!(unwrappedReturnType.flags & (8388608 /* IndexedAccess */ | 16777216 /* Conditional */)) || !couldContainTypeVariables(unwrappedReturnType)) {
83606
- checkTypeAssignableToAndOptionallyElaborate(unwrappedExprType, unwrappedReturnType, errorNode, effectiveExpr);
83607
- return;
83608
- }
83609
- if (checkTypeAssignableTo(
83610
- unwrappedExprType,
83611
- unwrappedReturnType,
83612
- /*errorNode*/
83613
- void 0
83614
- )) {
83615
- return;
83616
- }
83617
- let narrowPosition = node;
83618
- let narrowFlowNode = inReturnStatement && node.flowNode;
83619
- if (expr && isConditionalExpression(expr.parent)) {
83620
- narrowFlowNode = expr.parent.whenTrue === expr ? expr.parent.flowNodeWhenTrue : expr.parent.flowNodeWhenFalse;
83621
- narrowPosition = expr;
83622
- }
83623
- if (!narrowFlowNode) {
83624
- checkTypeAssignableToAndOptionallyElaborate(unwrappedExprType, unwrappedReturnType, errorNode, effectiveExpr);
83625
- return;
83626
- }
83627
- const allTypeParameters = appendTypeParameters(getOuterTypeParameters(
83628
- container,
83629
- /*includeThisTypes*/
83630
- false
83631
- ), getEffectiveTypeParameterDeclarations(container));
83632
- const narrowableTypeParameters = allTypeParameters && getNarrowableTypeParameters(allTypeParameters);
83633
- if (!narrowableTypeParameters || !narrowableTypeParameters.length || !isNarrowableReturnType(unwrappedReturnType)) {
83634
- checkTypeAssignableToAndOptionallyElaborate(unwrappedExprType, unwrappedReturnType, errorNode, effectiveExpr);
83635
- return;
83636
- }
83637
- const narrowedTypeParameters = [];
83638
- const narrowedTypes = [];
83639
- for (const [typeParam, symbol, reference] of narrowableTypeParameters) {
83640
- const narrowReference = factory.cloneNode(reference);
83641
- narrowReference.id = void 0;
83642
- getNodeLinks(narrowReference).resolvedSymbol = symbol;
83643
- setParent(narrowReference, narrowPosition.parent);
83644
- narrowReference.flowNode = narrowFlowNode;
83645
- const initialType = getNarrowableTypeForReference(
83646
- typeParam,
83647
- narrowReference,
83648
- /*checkMode*/
83649
- void 0,
83650
- /*forReturnTypeNarrowing*/
83651
- true
83652
- );
83653
- if (initialType === typeParam) {
83654
- continue;
83655
- }
83656
- const flowType = getFlowTypeOfReference(narrowReference, initialType);
83657
- const exprType2 = getTypeFromFlowType(flowType);
83658
- if (exprType2.flags & 3 /* AnyOrUnknown */ || isErrorType(exprType2) || exprType2 === typeParam || exprType2 === mapType(typeParam, getBaseConstraintOrType)) {
83659
- continue;
83660
- }
83661
- const narrowedType = getSubstitutionType(
83662
- typeParam,
83663
- exprType2,
83664
- /*isNarrowed*/
83665
- true
83666
- );
83667
- narrowedTypeParameters.push(typeParam);
83668
- narrowedTypes.push(narrowedType);
83669
- }
83670
- const narrowMapper = createTypeMapper(narrowedTypeParameters, narrowedTypes);
83671
- const narrowedReturnType = instantiateType(
83672
- unwrappedReturnType,
83673
- narrowMapper
83674
- );
83675
- if (expr) {
83676
- const links = getNodeLinks(expr);
83677
- if (!links.contextualReturnType) {
83678
- links.contextualReturnType = narrowedReturnType;
83679
- }
83680
- }
83681
- const narrowedExprType = expr ? checkExpression(expr) : undefinedType;
83682
- const narrowedUnwrappedExprType = functionFlags & 2 /* Async */ ? checkAwaitedType(
83683
- narrowedExprType,
83684
- /*withAlias*/
83685
- false,
83686
- node,
83687
- Diagnostics.The_return_type_of_an_async_function_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member
83688
- ) : narrowedExprType;
83689
- checkTypeAssignableToAndOptionallyElaborate(narrowedUnwrappedExprType, narrowedReturnType, errorNode, effectiveExpr);
83690
- }
83691
- function getNarrowableTypeParameters(candidates) {
83692
- const narrowableParams = [];
83693
- for (const typeParam of candidates) {
83694
- const constraint = getConstraintOfTypeParameter(typeParam);
83695
- if (!constraint || !(constraint.flags & 1048576 /* Union */)) continue;
83696
- if (typeParam.symbol && typeParam.symbol.declarations && typeParam.symbol.declarations.length === 1) {
83697
- const declaration = typeParam.symbol.declarations[0];
83698
- const container = isJSDocTemplateTag(declaration.parent) ? getJSDocHost(declaration.parent) : declaration.parent;
83699
- if (!isFunctionLike(container)) continue;
83700
- let reference;
83701
- let hasInvalidReference = false;
83702
- for (const paramDecl of container.parameters) {
83703
- const typeNode = getEffectiveTypeAnnotationNode(paramDecl);
83704
- if (!typeNode) continue;
83705
- if (isTypeParameterReferenced(typeParam, typeNode)) {
83706
- let candidateReference;
83707
- if (isTypeReferenceNode(typeNode) && isReferenceToTypeParameter(typeParam, typeNode) && (candidateReference = getValidParameterReference(paramDecl, constraint))) {
83708
- if (reference) {
83709
- hasInvalidReference = true;
83710
- break;
83711
- }
83712
- reference = candidateReference;
83713
- } else {
83714
- hasInvalidReference = true;
83715
- break;
83716
- }
83717
- }
83718
- }
83719
- if (!hasInvalidReference && reference) {
83720
- const symbol = getResolvedSymbol(reference);
83721
- if (symbol !== unknownSymbol) narrowableParams.push([typeParam, symbol, reference]);
83722
- }
83723
- }
83724
- }
83725
- return narrowableParams;
83726
- function getValidParameterReference(paramDecl, constraint) {
83727
- if (!isIdentifier(paramDecl.name)) return;
83728
- const isOptional = !!paramDecl.questionToken || isJSDocOptionalParameter(paramDecl);
83729
- if (isOptional && !containsUndefinedType(constraint)) return;
83730
- return paramDecl.name;
83731
- }
83732
- function isReferenceToTypeParameter(typeParam, node) {
83733
- return getTypeFromTypeReference(node) === typeParam;
83734
- }
83735
- function isTypeParameterReferenced(typeParam, node) {
83736
- return isReferenced(node);
83737
- function isReferenced(node2) {
83738
- if (isTypeReferenceNode(node2)) {
83739
- return isReferenceToTypeParameter(typeParam, node2);
83740
- }
83741
- if (isTypeQueryNode(node2)) {
83742
- return isTypeParameterPossiblyReferenced(typeParam, node2);
83743
- }
83744
- return !!forEachChild(node2, isReferenced);
83745
- }
83746
- }
83747
- }
83748
- function isNarrowableReturnType(returnType) {
83749
- return isConditionalType(returnType) ? isNarrowableConditionalType(returnType) : !!(returnType.indexType.flags & 262144 /* TypeParameter */);
83750
- }
83751
- function isNarrowableConditionalType(type, mapper) {
83752
- const typeArguments = mapper && map(type.root.outerTypeParameters, (t) => {
83753
- const mapped = getMappedType(t, mapper);
83754
- if (isNarrowingSubstitutionType(mapped)) {
83755
- return mapped.baseType;
83756
- }
83757
- return mapped;
83758
- });
83759
- const id = `${type.id}:${getTypeListId(typeArguments)}`;
83760
- let result = narrowableReturnTypeCache.get(id);
83761
- if (result === void 0) {
83762
- const nonNarrowingMapper = type.root.outerTypeParameters && typeArguments && createTypeMapper(type.root.outerTypeParameters, typeArguments);
83763
- const instantiatedType = instantiateType(type, nonNarrowingMapper);
83764
- result = isConditionalType(instantiatedType) && isNarrowableConditionalTypeWorker(instantiatedType);
83765
- narrowableReturnTypeCache.set(id, result);
83766
- }
83767
- return result;
83768
- }
83769
- function isNarrowableConditionalTypeWorker(type) {
83770
- if (!type.root.isDistributive) {
83771
- return false;
83772
- }
83773
- if (type.root.inferTypeParameters) {
83774
- return false;
83775
- }
83776
- if (!(type.checkType.flags & 262144 /* TypeParameter */)) {
83777
- return false;
83778
- }
83779
- const constraintType = getConstraintOfTypeParameter(type.checkType);
83780
- if (!constraintType || !(constraintType.flags & 1048576 /* Union */)) {
83781
- return false;
83782
- }
83783
- if (!everyType(type.extendsType, (extendsType) => some(
83784
- constraintType.types,
83785
- (constraintType2) => isTypeIdenticalTo(constraintType2, extendsType)
83786
- ))) {
83787
- return false;
83788
- }
83789
- const trueType2 = getTrueTypeFromConditionalType(type);
83790
- const isValidTrueType = isConditionalType(trueType2) ? isNarrowableConditionalType(trueType2) : true;
83791
- if (!isValidTrueType) return false;
83792
- const falseType2 = getFalseTypeFromConditionalType(type);
83793
- const isValidFalseType = isConditionalType(falseType2) ? isNarrowableConditionalType(falseType2) : falseType2 === neverType;
83794
- return isValidFalseType;
83795
- }
83796
- function isConditionalType(type) {
83797
- return !!(type.flags & 16777216 /* Conditional */);
83438
+ checkTypeAssignableToAndOptionallyElaborate(unwrappedExprType, unwrappedReturnType, errorNode, effectiveExpr);
83798
83439
  }
83799
83440
  function checkWithStatement(node) {
83800
83441
  if (!checkGrammarStatementInAmbientContext(node)) {
@@ -86592,7 +86233,7 @@ function createTypeChecker(host) {
86592
86233
  name,
86593
86234
  meaning,
86594
86235
  /*ignoreErrors*/
86595
- false,
86236
+ true,
86596
86237
  /*dontResolveAlias*/
86597
86238
  true
86598
86239
  );
@@ -86602,7 +86243,9 @@ function createTypeChecker(host) {
86602
86243
  return resolveEntityName(
86603
86244
  name,
86604
86245
  /*meaning*/
86605
- 1 /* FunctionScopedVariable */
86246
+ 1 /* FunctionScopedVariable */,
86247
+ /*ignoreErrors*/
86248
+ true
86606
86249
  );
86607
86250
  }
86608
86251
  return void 0;
@@ -86787,7 +86430,12 @@ function createTypeChecker(host) {
86787
86430
  }
86788
86431
  function getShorthandAssignmentValueSymbol(location) {
86789
86432
  if (location && location.kind === 304 /* ShorthandPropertyAssignment */) {
86790
- return resolveEntityName(location.name, 111551 /* Value */ | 2097152 /* Alias */);
86433
+ return resolveEntityName(
86434
+ location.name,
86435
+ 111551 /* Value */ | 2097152 /* Alias */,
86436
+ /*ignoreErrors*/
86437
+ true
86438
+ );
86791
86439
  }
86792
86440
  return void 0;
86793
86441
  }
@@ -86796,10 +86444,20 @@ function createTypeChecker(host) {
86796
86444
  const name = node.propertyName || node.name;
86797
86445
  return node.parent.parent.moduleSpecifier ? getExternalModuleMember(node.parent.parent, node) : name.kind === 11 /* StringLiteral */ ? void 0 : (
86798
86446
  // Skip for invalid syntax like this: export { "x" }
86799
- resolveEntityName(name, 111551 /* Value */ | 788968 /* Type */ | 1920 /* Namespace */ | 2097152 /* Alias */)
86447
+ resolveEntityName(
86448
+ name,
86449
+ 111551 /* Value */ | 788968 /* Type */ | 1920 /* Namespace */ | 2097152 /* Alias */,
86450
+ /*ignoreErrors*/
86451
+ true
86452
+ )
86800
86453
  );
86801
86454
  } else {
86802
- return resolveEntityName(node, 111551 /* Value */ | 788968 /* Type */ | 1920 /* Namespace */ | 2097152 /* Alias */);
86455
+ return resolveEntityName(
86456
+ node,
86457
+ 111551 /* Value */ | 788968 /* Type */ | 1920 /* Namespace */ | 2097152 /* Alias */,
86458
+ /*ignoreErrors*/
86459
+ true
86460
+ );
86803
86461
  }
86804
86462
  }
86805
86463
  function getTypeOfNode(node) {
@@ -112265,7 +111923,7 @@ function transformECMAScriptModule(context) {
112265
111923
  if (node === (importsAndRequiresToRewriteOrShim == null ? void 0 : importsAndRequiresToRewriteOrShim[0])) {
112266
111924
  return visitImportOrRequireCall(importsAndRequiresToRewriteOrShim.shift());
112267
111925
  }
112268
- break;
111926
+ // fallthrough
112269
111927
  default:
112270
111928
  if ((importsAndRequiresToRewriteOrShim == null ? void 0 : importsAndRequiresToRewriteOrShim.length) && rangeContainsRange(node, importsAndRequiresToRewriteOrShim[0])) {
112271
111929
  return visitEachChild(node, visitor, context);