typescript 5.7.0-dev.20241105 → 5.8.0-dev.20241106

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
@@ -17,8 +17,8 @@ and limitations under the License.
17
17
  "use strict";
18
18
 
19
19
  // src/compiler/corePublic.ts
20
- var versionMajorMinor = "5.7";
21
- var version = `${versionMajorMinor}.0-dev.20241105`;
20
+ var versionMajorMinor = "5.8";
21
+ var version = `${versionMajorMinor}.0-dev.20241106`;
22
22
 
23
23
  // src/compiler/core.ts
24
24
  var emptyArray = [];
@@ -3680,6 +3680,7 @@ 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";
3683
3684
  ObjectFlags3[ObjectFlags3["ContainsIntersections"] = 16777216] = "ContainsIntersections";
3684
3685
  ObjectFlags3[ObjectFlags3["IsUnknownLikeUnionComputed"] = 33554432] = "IsUnknownLikeUnionComputed";
3685
3686
  ObjectFlags3[ObjectFlags3["IsUnknownLikeUnion"] = 67108864] = "IsUnknownLikeUnion";
@@ -15067,7 +15068,7 @@ function tryGetModuleSpecifierFromDeclaration(node) {
15067
15068
  }
15068
15069
  }
15069
15070
  function shouldRewriteModuleSpecifier(specifier, compilerOptions) {
15070
- return !!compilerOptions.rewriteRelativeImportExtensions && pathIsRelative(specifier) && !isDeclarationFileName(specifier);
15071
+ return !!compilerOptions.rewriteRelativeImportExtensions && pathIsRelative(specifier) && !isDeclarationFileName(specifier) && hasTSFileExtension(specifier);
15071
15072
  }
15072
15073
  function getExternalModuleName(node) {
15073
15074
  switch (node.kind) {
@@ -22453,6 +22454,8 @@ function createNodeFactory(flags, baseFactory2) {
22453
22454
  node.colonToken = colonToken ?? createToken(59 /* ColonToken */);
22454
22455
  node.whenFalse = parenthesizerRules().parenthesizeBranchOfConditionalExpression(whenFalse);
22455
22456
  node.transformFlags |= propagateChildFlags(node.condition) | propagateChildFlags(node.questionToken) | propagateChildFlags(node.whenTrue) | propagateChildFlags(node.colonToken) | propagateChildFlags(node.whenFalse);
22457
+ node.flowNodeWhenFalse = void 0;
22458
+ node.flowNodeWhenTrue = void 0;
22456
22459
  return node;
22457
22460
  }
22458
22461
  function updateConditionalExpression(node, condition, questionToken, whenTrue, colonToken, whenFalse) {
@@ -24256,7 +24259,7 @@ function createNodeFactory(flags, baseFactory2) {
24256
24259
  function isIgnorableParen(node) {
24257
24260
  return isParenthesizedExpression(node) && nodeIsSynthesized(node) && nodeIsSynthesized(getSourceMapRange(node)) && nodeIsSynthesized(getCommentRange(node)) && !some(getSyntheticLeadingComments(node)) && !some(getSyntheticTrailingComments(node));
24258
24261
  }
24259
- function restoreOuterExpressions(outerExpression, innerExpression, kinds = 31 /* All */) {
24262
+ function restoreOuterExpressions(outerExpression, innerExpression, kinds = 63 /* All */) {
24260
24263
  if (outerExpression && isOuterExpression(outerExpression, kinds) && !isIgnorableParen(outerExpression)) {
24261
24264
  return updateOuterExpression(
24262
24265
  outerExpression,
@@ -24302,7 +24305,7 @@ function createNodeFactory(flags, baseFactory2) {
24302
24305
  }
24303
24306
  }
24304
24307
  function createCallBinding(expression, recordTempVariable, languageVersion, cacheIdentifiers = false) {
24305
- const callee = skipOuterExpressions(expression, 31 /* All */);
24308
+ const callee = skipOuterExpressions(expression, 63 /* All */);
24306
24309
  let thisArg;
24307
24310
  let target;
24308
24311
  if (isSuperProperty(callee)) {
@@ -27171,7 +27174,7 @@ function getJSDocTypeAssertionType(node) {
27171
27174
  Debug.assertIsDefined(type);
27172
27175
  return type;
27173
27176
  }
27174
- function isOuterExpression(node, kinds = 31 /* All */) {
27177
+ function isOuterExpression(node, kinds = 63 /* All */) {
27175
27178
  switch (node.kind) {
27176
27179
  case 217 /* ParenthesizedExpression */:
27177
27180
  if (kinds & -2147483648 /* ExcludeJSDocTypeAssertion */ && isJSDocTypeAssertion(node)) {
@@ -27180,8 +27183,9 @@ function isOuterExpression(node, kinds = 31 /* All */) {
27180
27183
  return (kinds & 1 /* Parentheses */) !== 0;
27181
27184
  case 216 /* TypeAssertionExpression */:
27182
27185
  case 234 /* AsExpression */:
27183
- case 238 /* SatisfiesExpression */:
27184
27186
  return (kinds & 2 /* TypeAssertions */) !== 0;
27187
+ case 238 /* SatisfiesExpression */:
27188
+ return (kinds & (2 /* TypeAssertions */ | 32 /* Satisfies */)) !== 0;
27185
27189
  case 233 /* ExpressionWithTypeArguments */:
27186
27190
  return (kinds & 16 /* ExpressionsWithTypeArguments */) !== 0;
27187
27191
  case 235 /* NonNullExpression */:
@@ -27191,13 +27195,13 @@ function isOuterExpression(node, kinds = 31 /* All */) {
27191
27195
  }
27192
27196
  return false;
27193
27197
  }
27194
- function skipOuterExpressions(node, kinds = 31 /* All */) {
27198
+ function skipOuterExpressions(node, kinds = 63 /* All */) {
27195
27199
  while (isOuterExpression(node, kinds)) {
27196
27200
  node = node.expression;
27197
27201
  }
27198
27202
  return node;
27199
27203
  }
27200
- function walkUpOuterExpressions(node, kinds = 31 /* All */) {
27204
+ function walkUpOuterExpressions(node, kinds = 63 /* All */) {
27201
27205
  let parent = node.parent;
27202
27206
  while (isOuterExpression(parent, kinds)) {
27203
27207
  parent = parent.parent;
@@ -36099,6 +36103,7 @@ var libEntries = [
36099
36103
  ["esnext.regexp", "lib.es2024.regexp.d.ts"],
36100
36104
  ["esnext.string", "lib.es2024.string.d.ts"],
36101
36105
  ["esnext.iterator", "lib.esnext.iterator.d.ts"],
36106
+ ["esnext.promise", "lib.esnext.promise.d.ts"],
36102
36107
  ["decorators", "lib.decorators.d.ts"],
36103
36108
  ["decorators.legacy", "lib.decorators.legacy.d.ts"]
36104
36109
  ];
@@ -41908,6 +41913,7 @@ function createBinder() {
41908
41913
  var preSwitchCaseFlow;
41909
41914
  var activeLabelList;
41910
41915
  var hasExplicitReturn;
41916
+ var inReturnPosition;
41911
41917
  var hasFlowEffects;
41912
41918
  var emitFlags;
41913
41919
  var inStrictMode;
@@ -41980,6 +41986,7 @@ function createBinder() {
41980
41986
  currentExceptionTarget = void 0;
41981
41987
  activeLabelList = void 0;
41982
41988
  hasExplicitReturn = false;
41989
+ inReturnPosition = false;
41983
41990
  hasFlowEffects = false;
41984
41991
  inAssignmentPattern = false;
41985
41992
  emitFlags = 0 /* None */;
@@ -42216,6 +42223,8 @@ function createBinder() {
42216
42223
  const saveContainer = container;
42217
42224
  const saveThisParentContainer = thisParentContainer;
42218
42225
  const savedBlockScopeContainer = blockScopeContainer;
42226
+ const savedInReturnPosition = inReturnPosition;
42227
+ if (node.kind === 219 /* ArrowFunction */ && node.body.kind !== 241 /* Block */) inReturnPosition = true;
42219
42228
  if (containerFlags & 1 /* IsContainer */) {
42220
42229
  if (node.kind !== 219 /* ArrowFunction */) {
42221
42230
  thisParentContainer = container;
@@ -42293,6 +42302,7 @@ function createBinder() {
42293
42302
  } else {
42294
42303
  bindChildren(node);
42295
42304
  }
42305
+ inReturnPosition = savedInReturnPosition;
42296
42306
  container = saveContainer;
42297
42307
  thisParentContainer = saveThisParentContainer;
42298
42308
  blockScopeContainer = savedBlockScopeContainer;
@@ -42744,7 +42754,10 @@ function createBinder() {
42744
42754
  currentFlow = finishFlowLabel(postIfLabel);
42745
42755
  }
42746
42756
  function bindReturnOrThrow(node) {
42757
+ const savedInReturnPosition = inReturnPosition;
42758
+ inReturnPosition = true;
42747
42759
  bind(node.expression);
42760
+ inReturnPosition = savedInReturnPosition;
42748
42761
  if (node.kind === 253 /* ReturnStatement */) {
42749
42762
  hasExplicitReturn = true;
42750
42763
  if (currentReturnTarget) {
@@ -43105,10 +43118,16 @@ function createBinder() {
43105
43118
  hasFlowEffects = false;
43106
43119
  bindCondition(node.condition, trueLabel, falseLabel);
43107
43120
  currentFlow = finishFlowLabel(trueLabel);
43121
+ if (inReturnPosition) {
43122
+ node.flowNodeWhenTrue = currentFlow;
43123
+ }
43108
43124
  bind(node.questionToken);
43109
43125
  bind(node.whenTrue);
43110
43126
  addAntecedent(postExpressionLabel, currentFlow);
43111
43127
  currentFlow = finishFlowLabel(falseLabel);
43128
+ if (inReturnPosition) {
43129
+ node.flowNodeWhenFalse = currentFlow;
43130
+ }
43112
43131
  bind(node.colonToken);
43113
43132
  bind(node.whenFalse);
43114
43133
  addAntecedent(postExpressionLabel, currentFlow);
@@ -46165,8 +46184,8 @@ function createTypeChecker(host) {
46165
46184
  writeSignature: (signature, enclosingDeclaration, flags, kind, writer) => {
46166
46185
  return signatureToString(signature, getParseTreeNode(enclosingDeclaration), flags, kind, writer);
46167
46186
  },
46168
- writeType: (type, enclosingDeclaration, flags, writer) => {
46169
- return typeToString(type, getParseTreeNode(enclosingDeclaration), flags, writer);
46187
+ writeType: (type, enclosingDeclaration, flags, writer, verbosityLevel, out) => {
46188
+ return typeToString(type, getParseTreeNode(enclosingDeclaration), flags, writer, verbosityLevel, out);
46170
46189
  },
46171
46190
  writeSymbol: (symbol, enclosingDeclaration, meaning, flags, writer) => {
46172
46191
  return symbolToString(symbol, getParseTreeNode(enclosingDeclaration), meaning, flags, writer);
@@ -46952,6 +46971,7 @@ function createTypeChecker(host) {
46952
46971
  [".jsx", ".jsx"],
46953
46972
  [".json", ".json"]
46954
46973
  ];
46974
+ var narrowableReturnTypeCache = /* @__PURE__ */ new Map();
46955
46975
  initializeTypeChecker();
46956
46976
  return checker;
46957
46977
  function isDefinitelyReferenceToGlobalSymbolObject(node) {
@@ -50087,14 +50107,18 @@ function createTypeChecker(host) {
50087
50107
  return writer2;
50088
50108
  }
50089
50109
  }
50090
- function typeToString(type, enclosingDeclaration, flags = 1048576 /* AllowUniqueESSymbolType */ | 16384 /* UseAliasDefinedOutsideCurrentScope */, writer = createTextWriter("")) {
50091
- const noTruncation = compilerOptions.noErrorTruncation || flags & 1 /* NoTruncation */;
50110
+ function typeToString(type, enclosingDeclaration, flags = 1048576 /* AllowUniqueESSymbolType */ | 16384 /* UseAliasDefinedOutsideCurrentScope */, writer = createTextWriter(""), verbosityLevel, out) {
50111
+ const noTruncation = compilerOptions.noErrorTruncation || flags & 1 /* NoTruncation */ || verbosityLevel !== void 0;
50092
50112
  const typeNode = nodeBuilder.typeToTypeNode(
50093
50113
  type,
50094
50114
  enclosingDeclaration,
50095
- toNodeBuilderFlags(flags) | 70221824 /* IgnoreErrors */ | (noTruncation ? 1 /* NoTruncation */ : 0 /* None */),
50115
+ toNodeBuilderFlags(flags) | 70221824 /* IgnoreErrors */ | (noTruncation ? 1 /* NoTruncation */ : 0),
50096
50116
  /*internalFlags*/
50097
- void 0
50117
+ void 0,
50118
+ /*tracker*/
50119
+ void 0,
50120
+ verbosityLevel,
50121
+ out
50098
50122
  );
50099
50123
  if (typeNode === void 0) return Debug.fail("should always get typenode");
50100
50124
  const printer = type !== unresolvedType ? createPrinterWithRemoveComments() : createPrinterWithDefaults();
@@ -50326,31 +50350,127 @@ function createTypeChecker(host) {
50326
50350
  };
50327
50351
  return {
50328
50352
  syntacticBuilderResolver,
50329
- typeToTypeNode: (type, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => typeToTypeNodeHelper(type, context)),
50330
- typePredicateToTypePredicateNode: (typePredicate, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => typePredicateToTypePredicateNodeHelper(typePredicate, context)),
50331
- serializeTypeForExpression: (expr, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => syntacticNodeBuilder.serializeTypeOfExpression(expr, context)),
50332
- serializeTypeForDeclaration: (declaration, symbol, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => syntacticNodeBuilder.serializeTypeOfDeclaration(declaration, symbol, context)),
50333
- serializeReturnTypeForSignature: (signature, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => syntacticNodeBuilder.serializeReturnTypeForSignature(signature, getSymbolOfDeclaration(signature), context)),
50334
- indexInfoToIndexSignatureDeclaration: (indexInfo, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => indexInfoToIndexSignatureDeclarationHelper(
50335
- indexInfo,
50336
- context,
50337
- /*typeNode*/
50338
- void 0
50339
- )),
50340
- signatureToSignatureDeclaration: (signature, kind, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => signatureToSignatureDeclarationHelper(signature, kind, context)),
50341
- symbolToEntityName: (symbol, meaning, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => symbolToName(
50342
- symbol,
50343
- context,
50344
- meaning,
50345
- /*expectsIdentifier*/
50346
- false
50347
- )),
50348
- symbolToExpression: (symbol, meaning, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => symbolToExpression(symbol, context, meaning)),
50349
- symbolToTypeParameterDeclarations: (symbol, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => typeParametersToTypeParameterDeclarations(symbol, context)),
50350
- symbolToParameterDeclaration: (symbol, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => symbolToParameterDeclaration(symbol, context)),
50351
- typeParameterToDeclaration: (parameter, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => typeParameterToDeclaration(parameter, context)),
50352
- symbolTableToDeclarationStatements: (symbolTable, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => symbolTableToDeclarationStatements(symbolTable, context)),
50353
- symbolToNode: (symbol, meaning, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => symbolToNode(symbol, context, meaning))
50353
+ typeToTypeNode: (type, enclosingDeclaration, flags, internalFlags, tracker, verbosityLevel, out) => withContext(enclosingDeclaration, flags, internalFlags, tracker, verbosityLevel, (context) => typeToTypeNodeHelper(type, context), out),
50354
+ typePredicateToTypePredicateNode: (typePredicate, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
50355
+ enclosingDeclaration,
50356
+ flags,
50357
+ internalFlags,
50358
+ tracker,
50359
+ /*verbosityLevel*/
50360
+ void 0,
50361
+ (context) => typePredicateToTypePredicateNodeHelper(typePredicate, context)
50362
+ ),
50363
+ serializeTypeForDeclaration: (declaration, symbol, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
50364
+ enclosingDeclaration,
50365
+ flags,
50366
+ internalFlags,
50367
+ tracker,
50368
+ /*verbosityLevel*/
50369
+ void 0,
50370
+ (context) => syntacticNodeBuilder.serializeTypeOfDeclaration(declaration, symbol, context)
50371
+ ),
50372
+ serializeReturnTypeForSignature: (signature, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
50373
+ enclosingDeclaration,
50374
+ flags,
50375
+ internalFlags,
50376
+ tracker,
50377
+ /*verbosityLevel*/
50378
+ void 0,
50379
+ (context) => syntacticNodeBuilder.serializeReturnTypeForSignature(signature, getSymbolOfDeclaration(signature), context)
50380
+ ),
50381
+ serializeTypeForExpression: (expr, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
50382
+ enclosingDeclaration,
50383
+ flags,
50384
+ internalFlags,
50385
+ tracker,
50386
+ /*verbosityLevel*/
50387
+ void 0,
50388
+ (context) => syntacticNodeBuilder.serializeTypeOfExpression(expr, context)
50389
+ ),
50390
+ indexInfoToIndexSignatureDeclaration: (indexInfo, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
50391
+ enclosingDeclaration,
50392
+ flags,
50393
+ internalFlags,
50394
+ tracker,
50395
+ /*verbosityLevel*/
50396
+ void 0,
50397
+ (context) => indexInfoToIndexSignatureDeclarationHelper(
50398
+ indexInfo,
50399
+ context,
50400
+ /*typeNode*/
50401
+ void 0
50402
+ )
50403
+ ),
50404
+ signatureToSignatureDeclaration: (signature, kind, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
50405
+ enclosingDeclaration,
50406
+ flags,
50407
+ internalFlags,
50408
+ tracker,
50409
+ /*verbosityLevel*/
50410
+ void 0,
50411
+ (context) => signatureToSignatureDeclarationHelper(signature, kind, context)
50412
+ ),
50413
+ symbolToEntityName: (symbol, meaning, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
50414
+ enclosingDeclaration,
50415
+ flags,
50416
+ internalFlags,
50417
+ tracker,
50418
+ /*verbosityLevel*/
50419
+ void 0,
50420
+ (context) => symbolToName(
50421
+ symbol,
50422
+ context,
50423
+ meaning,
50424
+ /*expectsIdentifier*/
50425
+ false
50426
+ )
50427
+ ),
50428
+ symbolToExpression: (symbol, meaning, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
50429
+ enclosingDeclaration,
50430
+ flags,
50431
+ internalFlags,
50432
+ tracker,
50433
+ /*verbosityLevel*/
50434
+ void 0,
50435
+ (context) => symbolToExpression(symbol, context, meaning)
50436
+ ),
50437
+ symbolToTypeParameterDeclarations: (symbol, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
50438
+ enclosingDeclaration,
50439
+ flags,
50440
+ internalFlags,
50441
+ tracker,
50442
+ /*verbosityLevel*/
50443
+ void 0,
50444
+ (context) => typeParametersToTypeParameterDeclarations(symbol, context)
50445
+ ),
50446
+ symbolToParameterDeclaration: (symbol, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
50447
+ enclosingDeclaration,
50448
+ flags,
50449
+ internalFlags,
50450
+ tracker,
50451
+ /*verbosityLevel*/
50452
+ void 0,
50453
+ (context) => symbolToParameterDeclaration(symbol, context)
50454
+ ),
50455
+ typeParameterToDeclaration: (parameter, enclosingDeclaration, flags, internalFlags, tracker, verbosityLevel) => withContext(enclosingDeclaration, flags, internalFlags, tracker, verbosityLevel, (context) => typeParameterToDeclaration(parameter, context)),
50456
+ symbolTableToDeclarationStatements: (symbolTable, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
50457
+ enclosingDeclaration,
50458
+ flags,
50459
+ internalFlags,
50460
+ tracker,
50461
+ /*verbosityLevel*/
50462
+ void 0,
50463
+ (context) => symbolTableToDeclarationStatements(symbolTable, context)
50464
+ ),
50465
+ symbolToNode: (symbol, meaning, enclosingDeclaration, flags, internalFlags, tracker) => withContext(
50466
+ enclosingDeclaration,
50467
+ flags,
50468
+ internalFlags,
50469
+ tracker,
50470
+ /*verbosityLevel*/
50471
+ void 0,
50472
+ (context) => symbolToNode(symbol, context, meaning)
50473
+ )
50354
50474
  };
50355
50475
  function getTypeFromTypeNode2(context, node, noMappedTypes) {
50356
50476
  const type = getTypeFromTypeNodeWithoutContext(node);
@@ -50392,7 +50512,7 @@ function createTypeChecker(host) {
50392
50512
  }
50393
50513
  return symbolToExpression(symbol, context, meaning);
50394
50514
  }
50395
- function withContext(enclosingDeclaration, flags, internalFlags, tracker, cb) {
50515
+ function withContext(enclosingDeclaration, flags, internalFlags, tracker, verbosityLevel, cb, out) {
50396
50516
  const moduleResolverHost = (tracker == null ? void 0 : tracker.trackSymbol) ? tracker.moduleResolverHost : (internalFlags || 0 /* None */) & 4 /* DoNotIncludeSymbolChain */ ? createBasicNodeBuilderModuleSpecifierResolutionHost(host) : void 0;
50397
50517
  const context = {
50398
50518
  enclosingDeclaration,
@@ -50400,6 +50520,7 @@ function createTypeChecker(host) {
50400
50520
  flags: flags || 0 /* None */,
50401
50521
  internalFlags: internalFlags || 0 /* None */,
50402
50522
  tracker: void 0,
50523
+ unfoldDepth: verbosityLevel ?? -1,
50403
50524
  encounteredError: false,
50404
50525
  suppressReportInferenceFallback: false,
50405
50526
  reportedDiagnostic: false,
@@ -50421,13 +50542,18 @@ function createTypeChecker(host) {
50421
50542
  typeParameterNamesByText: void 0,
50422
50543
  typeParameterNamesByTextNextNameCount: void 0,
50423
50544
  enclosingSymbolTypes: /* @__PURE__ */ new Map(),
50424
- mapper: void 0
50545
+ mapper: void 0,
50546
+ depth: 0,
50547
+ couldUnfoldMore: false
50425
50548
  };
50426
50549
  context.tracker = new SymbolTrackerImpl(context, tracker, moduleResolverHost);
50427
50550
  const resultingNode = cb(context);
50428
50551
  if (context.truncating && context.flags & 1 /* NoTruncation */) {
50429
50552
  context.tracker.reportTruncationError();
50430
50553
  }
50554
+ if (out) {
50555
+ out.couldUnfoldMore = context.couldUnfoldMore;
50556
+ }
50431
50557
  return context.encounteredError ? void 0 : resultingNode;
50432
50558
  }
50433
50559
  function addSymbolTypeToContext(context, symbol, type) {
@@ -50446,16 +50572,36 @@ function createTypeChecker(host) {
50446
50572
  function saveRestoreFlags(context) {
50447
50573
  const flags = context.flags;
50448
50574
  const internalFlags = context.internalFlags;
50575
+ const depth = context.depth;
50449
50576
  return restore;
50450
50577
  function restore() {
50451
50578
  context.flags = flags;
50452
50579
  context.internalFlags = internalFlags;
50580
+ context.depth = depth;
50453
50581
  }
50454
50582
  }
50455
50583
  function checkTruncationLength(context) {
50456
50584
  if (context.truncating) return context.truncating;
50457
50585
  return context.truncating = context.approximateLength > (context.flags & 1 /* NoTruncation */ ? noTruncationMaximumTruncationLength : defaultMaximumTruncationLength);
50458
50586
  }
50587
+ function couldUnfoldType(type, context) {
50588
+ var _a;
50589
+ if ((_a = context.visitedTypes) == null ? void 0 : _a.has(type.id)) {
50590
+ return false;
50591
+ }
50592
+ return context.depth < context.unfoldDepth || context.depth === context.unfoldDepth && !context.couldUnfoldMore;
50593
+ }
50594
+ function canUnfoldType(type, context) {
50595
+ var _a;
50596
+ if ((_a = context.visitedTypes) == null ? void 0 : _a.has(type.id)) {
50597
+ return false;
50598
+ }
50599
+ const result = context.depth < context.unfoldDepth;
50600
+ if (!result) {
50601
+ context.couldUnfoldMore = true;
50602
+ }
50603
+ return result;
50604
+ }
50459
50605
  function typeToTypeNodeHelper(type, context) {
50460
50606
  const restoreFlags = saveRestoreFlags(context);
50461
50607
  const typeNode = typeToTypeNodeWorker(type, context);
@@ -50603,16 +50749,27 @@ function createTypeChecker(host) {
50603
50749
  return factory.createThisTypeNode();
50604
50750
  }
50605
50751
  if (!inTypeAlias && type.aliasSymbol && (context.flags & 16384 /* UseAliasDefinedOutsideCurrentScope */ || isTypeSymbolAccessible(type.aliasSymbol, context.enclosingDeclaration))) {
50606
- const typeArgumentNodes = mapToTypeNodes(type.aliasTypeArguments, context);
50607
- if (isReservedMemberName(type.aliasSymbol.escapedName) && !(type.aliasSymbol.flags & 32 /* Class */)) return factory.createTypeReferenceNode(factory.createIdentifier(""), typeArgumentNodes);
50608
- if (length(typeArgumentNodes) === 1 && type.aliasSymbol === globalArrayType.symbol) {
50609
- return factory.createArrayTypeNode(typeArgumentNodes[0]);
50752
+ if (!canUnfoldType(type, context)) {
50753
+ const typeArgumentNodes = mapToTypeNodes(type.aliasTypeArguments, context);
50754
+ if (isReservedMemberName(type.aliasSymbol.escapedName) && !(type.aliasSymbol.flags & 32 /* Class */)) return factory.createTypeReferenceNode(factory.createIdentifier(""), typeArgumentNodes);
50755
+ if (length(typeArgumentNodes) === 1 && type.aliasSymbol === globalArrayType.symbol) {
50756
+ return factory.createArrayTypeNode(typeArgumentNodes[0]);
50757
+ }
50758
+ return symbolToTypeNode(type.aliasSymbol, context, 788968 /* Type */, typeArgumentNodes);
50610
50759
  }
50611
- return symbolToTypeNode(type.aliasSymbol, context, 788968 /* Type */, typeArgumentNodes);
50760
+ context.depth += 1;
50612
50761
  }
50613
50762
  const objectFlags = getObjectFlags(type);
50614
50763
  if (objectFlags & 4 /* Reference */) {
50615
50764
  Debug.assert(!!(type.flags & 524288 /* Object */));
50765
+ if (canUnfoldType(type, context)) {
50766
+ context.depth += 1;
50767
+ return createAnonymousTypeNode(
50768
+ type,
50769
+ /*forceClassExpansion*/
50770
+ true
50771
+ );
50772
+ }
50616
50773
  return type.node ? visitAndTransformType(type, typeReferenceToTypeNode) : typeReferenceToTypeNode(type);
50617
50774
  }
50618
50775
  if (type.flags & 262144 /* TypeParameter */ || objectFlags & 3 /* ClassOrInterface */) {
@@ -50642,6 +50799,14 @@ function createTypeChecker(host) {
50642
50799
  void 0
50643
50800
  );
50644
50801
  }
50802
+ if (objectFlags & 3 /* ClassOrInterface */ && canUnfoldType(type, context)) {
50803
+ context.depth += 1;
50804
+ return createAnonymousTypeNode(
50805
+ type,
50806
+ /*forceClassExpansion*/
50807
+ true
50808
+ );
50809
+ }
50645
50810
  if (type.symbol) {
50646
50811
  return symbolToTypeNode(type.symbol, context, 788968 /* Type */);
50647
50812
  }
@@ -50845,7 +51010,7 @@ function createTypeChecker(host) {
50845
51010
  }
50846
51011
  return result;
50847
51012
  }
50848
- function createAnonymousTypeNode(type2) {
51013
+ function createAnonymousTypeNode(type2, forceClassExpansion = false) {
50849
51014
  var _a2, _b2;
50850
51015
  const typeId = type2.id;
50851
51016
  const symbol = type2.symbol;
@@ -50868,7 +51033,7 @@ function createTypeChecker(host) {
50868
51033
  const isInstanceType = isClassInstanceSide(type2) ? 788968 /* Type */ : 111551 /* Value */;
50869
51034
  if (isJSConstructor(symbol.valueDeclaration)) {
50870
51035
  return symbolToTypeNode(symbol, context, isInstanceType);
50871
- } else if (symbol.flags & 32 /* Class */ && !getBaseTypeVariableOfClass(symbol) && !(symbol.valueDeclaration && isClassLike(symbol.valueDeclaration) && context.flags & 2048 /* WriteClassExpressionAsTypeLiteral */ && (!isClassDeclaration(symbol.valueDeclaration) || isSymbolAccessible(
51036
+ } else if (symbol.flags & 32 /* Class */ && !forceClassExpansion && !getBaseTypeVariableOfClass(symbol) && !(symbol.valueDeclaration && isClassLike(symbol.valueDeclaration) && context.flags & 2048 /* WriteClassExpressionAsTypeLiteral */ && (!isClassDeclaration(symbol.valueDeclaration) || isSymbolAccessible(
50872
51037
  symbol,
50873
51038
  context.enclosingDeclaration,
50874
51039
  isInstanceType,
@@ -50912,7 +51077,7 @@ function createTypeChecker(host) {
50912
51077
  if (id && !context.symbolDepth) {
50913
51078
  context.symbolDepth = /* @__PURE__ */ new Map();
50914
51079
  }
50915
- const links = context.enclosingDeclaration && getNodeLinks(context.enclosingDeclaration);
51080
+ const links = context.unfoldDepth >= 0 ? void 0 : context.enclosingDeclaration && getNodeLinks(context.enclosingDeclaration);
50916
51081
  const key = `${getTypeId(type2)}|${context.flags}|${context.internalFlags}`;
50917
51082
  if (links) {
50918
51083
  links.serializedTypes || (links.serializedTypes = /* @__PURE__ */ new Map());
@@ -51827,7 +51992,7 @@ function createTypeChecker(host) {
51827
51992
  return factory.createTypeParameterDeclaration(modifiers, name, constraintNode, defaultParameterNode);
51828
51993
  }
51829
51994
  function typeToTypeNodeHelperWithPossibleReusableTypeNode(type, typeNode, context) {
51830
- return typeNode && getTypeFromTypeNode2(context, typeNode) === type && syntacticNodeBuilder.tryReuseExistingTypeNode(context, typeNode) || typeToTypeNodeHelper(type, context);
51995
+ return !couldUnfoldType(type, context) && typeNode && getTypeFromTypeNode2(context, typeNode) === type && syntacticNodeBuilder.tryReuseExistingTypeNode(context, typeNode) || typeToTypeNodeHelper(type, context);
51831
51996
  }
51832
51997
  function typeParameterToDeclaration(type, context, constraint = getConstraintOfTypeParameter(type)) {
51833
51998
  const constraintNode = constraint && typeToTypeNodeHelperWithPossibleReusableTypeNode(constraint, getConstraintDeclaration(type), context);
@@ -52461,7 +52626,7 @@ function createTypeChecker(host) {
52461
52626
  let result;
52462
52627
  const addUndefinedForParameter = declaration && (isParameter(declaration) || isJSDocParameterTag(declaration)) && requiresAddingImplicitUndefined(declaration, context.enclosingDeclaration);
52463
52628
  const decl = declaration ?? symbol.valueDeclaration ?? getDeclarationWithTypeAnnotation(symbol) ?? ((_a = symbol.declarations) == null ? void 0 : _a[0]);
52464
- if (decl) {
52629
+ if (!couldUnfoldType(type, context) && decl) {
52465
52630
  if (isAccessor(decl)) {
52466
52631
  result = syntacticNodeBuilder.serializeTypeOfAccessor(decl, symbol, context);
52467
52632
  } else if (hasInferredType(decl) && !nodeIsSynthesized(decl) && !(getObjectFlags(type) & 196608 /* RequiresWidening */)) {
@@ -59183,11 +59348,14 @@ function createTypeChecker(host) {
59183
59348
  function isNoInferType(type) {
59184
59349
  return !!(type.flags & 33554432 /* Substitution */ && type.constraint.flags & 2 /* Unknown */);
59185
59350
  }
59186
- function getSubstitutionType(baseType, constraint) {
59187
- return constraint.flags & 3 /* AnyOrUnknown */ || constraint === baseType || baseType.flags & 1 /* Any */ ? baseType : getOrCreateSubstitutionType(baseType, constraint);
59351
+ function isNarrowingSubstitutionType(type) {
59352
+ return !!(type.flags & 33554432 /* Substitution */ && type.objectFlags & 16777216 /* IsNarrowingType */);
59353
+ }
59354
+ function getSubstitutionType(baseType, constraint, isNarrowed) {
59355
+ return constraint.flags & 3 /* AnyOrUnknown */ || constraint === baseType || baseType.flags & 1 /* Any */ ? baseType : getOrCreateSubstitutionType(baseType, constraint, isNarrowed);
59188
59356
  }
59189
- function getOrCreateSubstitutionType(baseType, constraint) {
59190
- const id = `${getTypeId(baseType)}>${getTypeId(constraint)}`;
59357
+ function getOrCreateSubstitutionType(baseType, constraint, isNarrowed) {
59358
+ const id = `${getTypeId(baseType)}>${getTypeId(constraint)}${isNarrowed ? ">N" : ""}`;
59191
59359
  const cached = substitutionTypes.get(id);
59192
59360
  if (cached) {
59193
59361
  return cached;
@@ -59195,6 +59363,9 @@ function createTypeChecker(host) {
59195
59363
  const result = createType(33554432 /* Substitution */);
59196
59364
  result.baseType = baseType;
59197
59365
  result.constraint = constraint;
59366
+ if (isNarrowed) {
59367
+ result.objectFlags |= 16777216 /* IsNarrowingType */;
59368
+ }
59198
59369
  substitutionTypes.set(id, result);
59199
59370
  return result;
59200
59371
  }
@@ -61397,7 +61568,7 @@ function createTypeChecker(host) {
61397
61568
  function isDeferredType(type, checkTuples) {
61398
61569
  return isGenericType(type) || checkTuples && isTupleType(type) && some(getElementTypes(type), isGenericType);
61399
61570
  }
61400
- function getConditionalType(root, mapper, forConstraint, aliasSymbol, aliasTypeArguments) {
61571
+ function getConditionalType(root, mapper, forConstraint, aliasSymbol, aliasTypeArguments, forNarrowing) {
61401
61572
  let result;
61402
61573
  let extraTypes;
61403
61574
  let tailCount = 0;
@@ -61414,10 +61585,11 @@ function createTypeChecker(host) {
61414
61585
  if (checkType === wildcardType || extendsType === wildcardType) {
61415
61586
  return wildcardType;
61416
61587
  }
61588
+ const effectiveCheckType = forNarrowing && isNarrowingSubstitutionType(checkType) ? checkType.constraint : checkType;
61417
61589
  const checkTypeNode = skipTypeParentheses(root.node.checkType);
61418
61590
  const extendsTypeNode = skipTypeParentheses(root.node.extendsType);
61419
61591
  const checkTuples = isSimpleTupleType(checkTypeNode) && isSimpleTupleType(extendsTypeNode) && length(checkTypeNode.elements) === length(extendsTypeNode.elements);
61420
- const checkTypeDeferred = isDeferredType(checkType, checkTuples);
61592
+ const checkTypeDeferred = isDeferredType(effectiveCheckType, checkTuples);
61421
61593
  let combinedMapper;
61422
61594
  if (root.inferTypeParameters) {
61423
61595
  const context = createInferenceContext(
@@ -61436,8 +61608,8 @@ function createTypeChecker(host) {
61436
61608
  }
61437
61609
  const inferredExtendsType = combinedMapper ? instantiateType(root.extendsType, combinedMapper) : extendsType;
61438
61610
  if (!checkTypeDeferred && !isDeferredType(inferredExtendsType, checkTuples)) {
61439
- if (!(inferredExtendsType.flags & 3 /* AnyOrUnknown */) && (checkType.flags & 1 /* Any */ || !isTypeAssignableTo(getPermissiveInstantiation(checkType), getPermissiveInstantiation(inferredExtendsType)))) {
61440
- if (checkType.flags & 1 /* Any */ || forConstraint && !(inferredExtendsType.flags & 131072 /* Never */) && someType(getPermissiveInstantiation(inferredExtendsType), (t) => isTypeAssignableTo(t, getPermissiveInstantiation(checkType)))) {
61611
+ if (!(inferredExtendsType.flags & 3 /* AnyOrUnknown */) && (effectiveCheckType.flags & 1 /* Any */ || !isTypeAssignableTo(getPermissiveInstantiation(effectiveCheckType), getPermissiveInstantiation(inferredExtendsType)))) {
61612
+ if (effectiveCheckType.flags & 1 /* Any */ || forConstraint && !(inferredExtendsType.flags & 131072 /* Never */) && someType(getPermissiveInstantiation(inferredExtendsType), (t) => isTypeAssignableTo(t, getPermissiveInstantiation(effectiveCheckType)))) {
61441
61613
  (extraTypes || (extraTypes = [])).push(instantiateType(getTypeFromTypeNode(root.node.trueType), combinedMapper || mapper));
61442
61614
  }
61443
61615
  const falseType2 = getTypeFromTypeNode(root.node.falseType);
@@ -61454,7 +61626,7 @@ function createTypeChecker(host) {
61454
61626
  result = instantiateType(falseType2, mapper);
61455
61627
  break;
61456
61628
  }
61457
- if (inferredExtendsType.flags & 3 /* AnyOrUnknown */ || isTypeAssignableTo(getRestrictiveInstantiation(checkType), getRestrictiveInstantiation(inferredExtendsType))) {
61629
+ if (inferredExtendsType.flags & 3 /* AnyOrUnknown */ || isTypeAssignableTo(getRestrictiveInstantiation(effectiveCheckType), getRestrictiveInstantiation(inferredExtendsType))) {
61458
61630
  const trueType2 = getTypeFromTypeNode(root.node.trueType);
61459
61631
  const trueMapper = combinedMapper || mapper;
61460
61632
  if (canTailRecurse(trueType2, trueMapper)) {
@@ -62420,8 +62592,39 @@ function createTypeChecker(host) {
62420
62592
  if (!result) {
62421
62593
  const newMapper = createTypeMapper(root.outerTypeParameters, typeArguments);
62422
62594
  const checkType = root.checkType;
62423
- const distributionType = root.isDistributive ? getReducedType(getMappedType(checkType, newMapper)) : void 0;
62424
- 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);
62595
+ let distributionType = root.isDistributive ? getReducedType(getMappedType(checkType, newMapper)) : void 0;
62596
+ let narrowingBaseType;
62597
+ const forNarrowing = distributionType && isNarrowingSubstitutionType(distributionType) && isNarrowableConditionalType(type, mapper);
62598
+ if (forNarrowing) {
62599
+ narrowingBaseType = distributionType.baseType;
62600
+ distributionType = getReducedType(distributionType.constraint);
62601
+ }
62602
+ if (distributionType && checkType !== distributionType && distributionType.flags & (1048576 /* Union */ | 131072 /* Never */)) {
62603
+ if (narrowingBaseType) {
62604
+ result = mapTypeToIntersection(
62605
+ distributionType,
62606
+ (t) => getConditionalType(
62607
+ root,
62608
+ prependTypeMapping(checkType, getSubstitutionType(
62609
+ narrowingBaseType,
62610
+ t,
62611
+ /*isNarrowed*/
62612
+ true
62613
+ ), newMapper),
62614
+ forConstraint,
62615
+ /*aliasSymbol*/
62616
+ void 0,
62617
+ /*aliasTypeArguments*/
62618
+ void 0,
62619
+ forNarrowing
62620
+ )
62621
+ );
62622
+ } else {
62623
+ result = mapTypeWithAlias(distributionType, (t) => getConditionalType(root, prependTypeMapping(checkType, t, newMapper), forConstraint), aliasSymbol, aliasTypeArguments);
62624
+ }
62625
+ } else {
62626
+ result = getConditionalType(root, newMapper, forConstraint, aliasSymbol, aliasTypeArguments, forNarrowing);
62627
+ }
62425
62628
  root.instantiations.set(id, result);
62426
62629
  }
62427
62630
  return result;
@@ -63564,10 +63767,12 @@ function createTypeChecker(host) {
63564
63767
  function shouldNormalizeIntersection(type) {
63565
63768
  let hasInstantiable = false;
63566
63769
  let hasNullableOrEmpty = false;
63770
+ let hasSubstitution = false;
63567
63771
  for (const t of type.types) {
63568
63772
  hasInstantiable || (hasInstantiable = !!(t.flags & 465829888 /* Instantiable */));
63569
63773
  hasNullableOrEmpty || (hasNullableOrEmpty = !!(t.flags & 98304 /* Nullable */) || isEmptyAnonymousObjectType(t));
63570
- if (hasInstantiable && hasNullableOrEmpty) return true;
63774
+ hasSubstitution || (hasSubstitution = isNarrowingSubstitutionType(t));
63775
+ if (hasInstantiable && hasNullableOrEmpty || hasSubstitution) return true;
63571
63776
  }
63572
63777
  return false;
63573
63778
  }
@@ -68726,6 +68931,18 @@ function createTypeChecker(host) {
68726
68931
  }
68727
68932
  return changed ? mappedTypes && getUnionType(mappedTypes, noReductions ? 0 /* None */ : 1 /* Literal */) : type;
68728
68933
  }
68934
+ function mapTypeToIntersection(type, mapper) {
68935
+ if (type.flags & 131072 /* Never */) {
68936
+ return type;
68937
+ }
68938
+ if (!(type.flags & 1048576 /* Union */)) {
68939
+ return mapper(type);
68940
+ }
68941
+ const origin = type.origin;
68942
+ const types = origin && origin.flags & 1048576 /* Union */ ? origin.types : type.types;
68943
+ const mappedTypes = types.map((t) => t.flags & 1048576 /* Union */ ? mapTypeToIntersection(t, mapper) : mapper(t));
68944
+ return getIntersectionType(mappedTypes);
68945
+ }
68729
68946
  function mapTypeWithAlias(type, mapper, aliasSymbol, aliasTypeArguments) {
68730
68947
  return type.flags & 1048576 /* Union */ && aliasSymbol ? getUnionType(map(type.types, mapper), 1 /* Literal */, aliasSymbol, aliasTypeArguments) : mapType(type, mapper);
68731
68948
  }
@@ -70308,11 +70525,11 @@ function createTypeChecker(host) {
70308
70525
  ));
70309
70526
  return contextualType && !isGenericType(contextualType);
70310
70527
  }
70311
- function getNarrowableTypeForReference(type, reference, checkMode) {
70528
+ function getNarrowableTypeForReference(type, reference, checkMode, forReturnTypeNarrowing) {
70312
70529
  if (isNoInferType(type)) {
70313
70530
  type = type.baseType;
70314
70531
  }
70315
- const substituteConstraints = !(checkMode && checkMode & 2 /* Inferential */) && someType(type, isGenericTypeWithUnionConstraint) && (isConstraintPosition(type, reference) || hasContextualTypeWithNoGenericTypes(reference, checkMode));
70532
+ const substituteConstraints = !(checkMode && checkMode & 2 /* Inferential */) && someType(type, isGenericTypeWithUnionConstraint) && (forReturnTypeNarrowing || isConstraintPosition(type, reference) || hasContextualTypeWithNoGenericTypes(reference, checkMode));
70316
70533
  return substituteConstraints ? mapType(type, getBaseConstraintOrType) : type;
70317
70534
  }
70318
70535
  function isExportOrExportExpression(location) {
@@ -71437,9 +71654,16 @@ function createTypeChecker(host) {
71437
71654
  function getContextualTypeForReturnExpression(node, contextFlags) {
71438
71655
  const func = getContainingFunction(node);
71439
71656
  if (func) {
71657
+ const functionFlags = getFunctionFlags(func);
71658
+ const links = getNodeLinks(node);
71659
+ if (links.contextualReturnType) {
71660
+ if (functionFlags & 2 /* Async */) {
71661
+ return getUnionType([links.contextualReturnType, createPromiseLikeType(links.contextualReturnType)]);
71662
+ }
71663
+ return links.contextualReturnType;
71664
+ }
71440
71665
  let contextualReturnType = getContextualReturnType(func, contextFlags);
71441
71666
  if (contextualReturnType) {
71442
- const functionFlags = getFunctionFlags(func);
71443
71667
  if (functionFlags & 1 /* Generator */) {
71444
71668
  const isAsyncGenerator = (functionFlags & 2 /* Async */) !== 0;
71445
71669
  if (contextualReturnType.flags & 1048576 /* Union */) {
@@ -72137,6 +72361,13 @@ function createTypeChecker(host) {
72137
72361
  if (index >= 0) {
72138
72362
  return contextualTypes[index];
72139
72363
  }
72364
+ const links = getNodeLinks(node);
72365
+ if (links.contextualReturnType) {
72366
+ if (node.flags & 65536 /* AwaitContext */) {
72367
+ return getUnionType([links.contextualReturnType, createPromiseLikeType(links.contextualReturnType)]);
72368
+ }
72369
+ return links.contextualReturnType;
72370
+ }
72140
72371
  const { parent } = node;
72141
72372
  switch (parent.kind) {
72142
72373
  case 260 /* VariableDeclaration */:
@@ -74813,8 +75044,8 @@ function createTypeChecker(host) {
74813
75044
  }
74814
75045
  }
74815
75046
  function getEffectiveCheckNode(argument) {
74816
- argument = skipParentheses(argument);
74817
- return isSatisfiesExpression(argument) ? skipParentheses(argument.expression) : argument;
75047
+ const flags = isInJSFile(argument) ? 1 /* Parentheses */ | 32 /* Satisfies */ | -2147483648 /* ExcludeJSDocTypeAssertion */ : 1 /* Parentheses */ | 32 /* Satisfies */;
75048
+ return skipOuterExpressions(argument, flags);
74818
75049
  }
74819
75050
  function getSignatureApplicabilityError(node, args, signature, relation, checkMode, reportErrors2, containingMessageChain, inferenceContext) {
74820
75051
  const errorOutputContainer = { errors: void 0, skipLogging: true };
@@ -75239,11 +75470,16 @@ function createTypeChecker(host) {
75239
75470
  if (!result) {
75240
75471
  result = chooseOverload(candidates, assignableRelation, isSingleNonGenericCandidate, signatureHelpTrailingComma);
75241
75472
  }
75473
+ const links = getNodeLinks(node);
75474
+ if (links.resolvedSignature !== resolvingSignature && !candidatesOutArray) {
75475
+ Debug.assert(links.resolvedSignature);
75476
+ return links.resolvedSignature;
75477
+ }
75242
75478
  if (result) {
75243
75479
  return result;
75244
75480
  }
75245
75481
  result = getCandidateForOverloadFailure(node, candidates, args, !!candidatesOutArray, checkMode);
75246
- getNodeLinks(node).resolvedSignature = result;
75482
+ links.resolvedSignature = result;
75247
75483
  if (reportErrors2) {
75248
75484
  if (!headMessage && isInstanceof) {
75249
75485
  headMessage = Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_assignable_to_the_first_argument_of_the_right_hand_side_s_Symbol_hasInstance_method;
@@ -76127,12 +76363,9 @@ function createTypeChecker(host) {
76127
76363
  resolutionStart = resolutionTargets.length;
76128
76364
  }
76129
76365
  links.resolvedSignature = resolvingSignature;
76130
- let result = resolveSignature(node, candidatesOutArray, checkMode || 0 /* Normal */);
76366
+ const result = resolveSignature(node, candidatesOutArray, checkMode || 0 /* Normal */);
76131
76367
  resolutionStart = saveResolutionStart;
76132
76368
  if (result !== resolvingSignature) {
76133
- if (links.resolvedSignature !== resolvingSignature) {
76134
- result = links.resolvedSignature;
76135
- }
76136
76369
  links.resolvedSignature = flowLoopStart === flowLoopCount ? result : cached;
76137
76370
  }
76138
76371
  return result;
@@ -77808,19 +78041,7 @@ function createTypeChecker(host) {
77808
78041
  const exprType = checkExpression(node.body);
77809
78042
  const returnOrPromisedType = returnType && unwrapReturnType(returnType, functionFlags);
77810
78043
  if (returnOrPromisedType) {
77811
- const effectiveCheckNode = getEffectiveCheckNode(node.body);
77812
- if ((functionFlags & 3 /* AsyncGenerator */) === 2 /* Async */) {
77813
- const awaitedType = checkAwaitedType(
77814
- exprType,
77815
- /*withAlias*/
77816
- false,
77817
- effectiveCheckNode,
77818
- Diagnostics.The_return_type_of_an_async_function_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member
77819
- );
77820
- checkTypeAssignableToAndOptionallyElaborate(awaitedType, returnOrPromisedType, effectiveCheckNode, effectiveCheckNode);
77821
- } else {
77822
- checkTypeAssignableToAndOptionallyElaborate(exprType, returnOrPromisedType, effectiveCheckNode, effectiveCheckNode);
77823
- }
78044
+ checkReturnExpression(node, returnOrPromisedType, node.body, node.body, exprType);
77824
78045
  }
77825
78046
  }
77826
78047
  }
@@ -77903,7 +78124,7 @@ function createTypeChecker(host) {
77903
78124
  return false;
77904
78125
  }
77905
78126
  function checkReferenceExpression(expr, invalidReferenceMessage, invalidOptionalChainMessage) {
77906
- const node = skipOuterExpressions(expr, 6 /* Assertions */ | 1 /* Parentheses */);
78127
+ const node = skipOuterExpressions(expr, 38 /* Assertions */ | 1 /* Parentheses */);
77907
78128
  if (node.kind !== 80 /* Identifier */ && !isAccessExpression(node)) {
77908
78129
  error(expr, invalidReferenceMessage);
77909
78130
  return false;
@@ -78554,7 +78775,7 @@ function createTypeChecker(host) {
78554
78775
  if (isBinaryExpression(right) && (right.operatorToken.kind === 57 /* BarBarToken */ || right.operatorToken.kind === 56 /* AmpersandAmpersandToken */)) {
78555
78776
  grammarErrorOnNode(right, Diagnostics._0_and_1_operations_cannot_be_mixed_without_parentheses, tokenToString(right.operatorToken.kind), tokenToString(operatorToken.kind));
78556
78777
  }
78557
- const leftTarget = skipOuterExpressions(left, 31 /* All */);
78778
+ const leftTarget = skipOuterExpressions(left, 63 /* All */);
78558
78779
  const nullishSemantics = getSyntacticNullishnessSemantics(leftTarget);
78559
78780
  if (nullishSemantics !== 3 /* Sometimes */) {
78560
78781
  if (node.parent.kind === 226 /* BinaryExpression */) {
@@ -83044,7 +83265,6 @@ function createTypeChecker(host) {
83044
83265
  }
83045
83266
  const signature = getSignatureFromDeclaration(container);
83046
83267
  const returnType = getReturnTypeOfSignature(signature);
83047
- const functionFlags = getFunctionFlags(container);
83048
83268
  if (strictNullChecks || node.expression || returnType.flags & 131072 /* Never */) {
83049
83269
  const exprType = node.expression ? checkExpressionCached(node.expression) : undefinedType;
83050
83270
  if (container.kind === 178 /* SetAccessor */) {
@@ -83052,26 +83272,249 @@ function createTypeChecker(host) {
83052
83272
  error(node, Diagnostics.Setters_cannot_return_a_value);
83053
83273
  }
83054
83274
  } else if (container.kind === 176 /* Constructor */) {
83055
- if (node.expression && !checkTypeAssignableToAndOptionallyElaborate(exprType, returnType, node, node.expression)) {
83275
+ const exprType2 = node.expression ? checkExpressionCached(node.expression) : undefinedType;
83276
+ if (node.expression && !checkTypeAssignableToAndOptionallyElaborate(exprType2, returnType, node, node.expression)) {
83056
83277
  error(node, Diagnostics.Return_type_of_constructor_signature_must_be_assignable_to_the_instance_type_of_the_class);
83057
83278
  }
83058
83279
  } else if (getReturnTypeFromAnnotation(container)) {
83059
- const unwrappedReturnType = unwrapReturnType(returnType, functionFlags) ?? returnType;
83060
- const unwrappedExprType = functionFlags & 2 /* Async */ ? checkAwaitedType(
83061
- exprType,
83062
- /*withAlias*/
83063
- false,
83064
- node,
83065
- Diagnostics.The_return_type_of_an_async_function_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member
83066
- ) : exprType;
83067
- if (unwrappedReturnType) {
83068
- checkTypeAssignableToAndOptionallyElaborate(unwrappedExprType, unwrappedReturnType, node, node.expression);
83069
- }
83280
+ const unwrappedReturnType = unwrapReturnType(returnType, getFunctionFlags(container)) ?? returnType;
83281
+ checkReturnExpression(container, unwrappedReturnType, node, node.expression, exprType);
83070
83282
  }
83071
83283
  } else if (container.kind !== 176 /* Constructor */ && compilerOptions.noImplicitReturns && !isUnwrappedReturnTypeUndefinedVoidOrAny(container, returnType)) {
83072
83284
  error(node, Diagnostics.Not_all_code_paths_return_a_value);
83073
83285
  }
83074
83286
  }
83287
+ function checkReturnExpression(container, unwrappedReturnType, node, expr, exprType, inConditionalExpression = false) {
83288
+ const excludeJSDocTypeAssertions = isInJSFile(node);
83289
+ const functionFlags = getFunctionFlags(container);
83290
+ if (expr) {
83291
+ const unwrappedExpr = skipParentheses(expr, excludeJSDocTypeAssertions);
83292
+ if (isConditionalExpression(unwrappedExpr)) {
83293
+ checkReturnExpression(
83294
+ container,
83295
+ unwrappedReturnType,
83296
+ node,
83297
+ unwrappedExpr.whenTrue,
83298
+ checkExpression(unwrappedExpr.whenTrue),
83299
+ /*inConditionalExpression*/
83300
+ true
83301
+ );
83302
+ checkReturnExpression(
83303
+ container,
83304
+ unwrappedReturnType,
83305
+ node,
83306
+ unwrappedExpr.whenFalse,
83307
+ checkExpression(unwrappedExpr.whenFalse),
83308
+ /*inConditionalExpression*/
83309
+ true
83310
+ );
83311
+ return;
83312
+ }
83313
+ }
83314
+ const inReturnStatement = node.kind === 253 /* ReturnStatement */;
83315
+ const unwrappedExprType = functionFlags & 2 /* Async */ ? checkAwaitedType(
83316
+ exprType,
83317
+ /*withAlias*/
83318
+ false,
83319
+ node,
83320
+ Diagnostics.The_return_type_of_an_async_function_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member
83321
+ ) : exprType;
83322
+ const effectiveExpr = expr && getEffectiveCheckNode(expr);
83323
+ const errorNode = inReturnStatement && !inConditionalExpression ? node : effectiveExpr;
83324
+ if (!(unwrappedReturnType.flags & (8388608 /* IndexedAccess */ | 16777216 /* Conditional */)) || !couldContainTypeVariables(unwrappedReturnType)) {
83325
+ checkTypeAssignableToAndOptionallyElaborate(unwrappedExprType, unwrappedReturnType, errorNode, effectiveExpr);
83326
+ return;
83327
+ }
83328
+ if (checkTypeAssignableTo(
83329
+ unwrappedExprType,
83330
+ unwrappedReturnType,
83331
+ /*errorNode*/
83332
+ void 0
83333
+ )) {
83334
+ return;
83335
+ }
83336
+ let narrowPosition = node;
83337
+ let narrowFlowNode = inReturnStatement && node.flowNode;
83338
+ if (expr && isConditionalExpression(expr.parent)) {
83339
+ narrowFlowNode = expr.parent.whenTrue === expr ? expr.parent.flowNodeWhenTrue : expr.parent.flowNodeWhenFalse;
83340
+ narrowPosition = expr;
83341
+ }
83342
+ if (!narrowFlowNode) {
83343
+ checkTypeAssignableToAndOptionallyElaborate(unwrappedExprType, unwrappedReturnType, errorNode, effectiveExpr);
83344
+ return;
83345
+ }
83346
+ const allTypeParameters = appendTypeParameters(getOuterTypeParameters(
83347
+ container,
83348
+ /*includeThisTypes*/
83349
+ false
83350
+ ), getEffectiveTypeParameterDeclarations(container));
83351
+ const narrowableTypeParameters = allTypeParameters && getNarrowableTypeParameters(allTypeParameters);
83352
+ if (!narrowableTypeParameters || !narrowableTypeParameters.length || !isNarrowableReturnType(unwrappedReturnType)) {
83353
+ checkTypeAssignableToAndOptionallyElaborate(unwrappedExprType, unwrappedReturnType, errorNode, effectiveExpr);
83354
+ return;
83355
+ }
83356
+ const narrowedTypeParameters = [];
83357
+ const narrowedTypes = [];
83358
+ for (const [typeParam, symbol, reference] of narrowableTypeParameters) {
83359
+ const narrowReference = factory.cloneNode(reference);
83360
+ narrowReference.id = void 0;
83361
+ getNodeLinks(narrowReference).resolvedSymbol = symbol;
83362
+ setParent(narrowReference, narrowPosition.parent);
83363
+ narrowReference.flowNode = narrowFlowNode;
83364
+ const initialType = getNarrowableTypeForReference(
83365
+ typeParam,
83366
+ narrowReference,
83367
+ /*checkMode*/
83368
+ void 0,
83369
+ /*forReturnTypeNarrowing*/
83370
+ true
83371
+ );
83372
+ if (initialType === typeParam) {
83373
+ continue;
83374
+ }
83375
+ const flowType = getFlowTypeOfReference(narrowReference, initialType);
83376
+ const exprType2 = getTypeFromFlowType(flowType);
83377
+ if (exprType2.flags & 3 /* AnyOrUnknown */ || isErrorType(exprType2) || exprType2 === typeParam || exprType2 === mapType(typeParam, getBaseConstraintOrType)) {
83378
+ continue;
83379
+ }
83380
+ const narrowedType = getSubstitutionType(
83381
+ typeParam,
83382
+ exprType2,
83383
+ /*isNarrowed*/
83384
+ true
83385
+ );
83386
+ narrowedTypeParameters.push(typeParam);
83387
+ narrowedTypes.push(narrowedType);
83388
+ }
83389
+ const narrowMapper = createTypeMapper(narrowedTypeParameters, narrowedTypes);
83390
+ const narrowedReturnType = instantiateType(
83391
+ unwrappedReturnType,
83392
+ narrowMapper
83393
+ );
83394
+ if (expr) {
83395
+ const links = getNodeLinks(expr);
83396
+ if (!links.contextualReturnType) {
83397
+ links.contextualReturnType = narrowedReturnType;
83398
+ }
83399
+ }
83400
+ const narrowedExprType = expr ? checkExpression(expr) : undefinedType;
83401
+ const narrowedUnwrappedExprType = functionFlags & 2 /* Async */ ? checkAwaitedType(
83402
+ narrowedExprType,
83403
+ /*withAlias*/
83404
+ false,
83405
+ node,
83406
+ Diagnostics.The_return_type_of_an_async_function_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member
83407
+ ) : narrowedExprType;
83408
+ checkTypeAssignableToAndOptionallyElaborate(narrowedUnwrappedExprType, narrowedReturnType, errorNode, effectiveExpr);
83409
+ }
83410
+ function getNarrowableTypeParameters(candidates) {
83411
+ const narrowableParams = [];
83412
+ for (const typeParam of candidates) {
83413
+ const constraint = getConstraintOfTypeParameter(typeParam);
83414
+ if (!constraint || !(constraint.flags & 1048576 /* Union */)) continue;
83415
+ if (typeParam.symbol && typeParam.symbol.declarations && typeParam.symbol.declarations.length === 1) {
83416
+ const declaration = typeParam.symbol.declarations[0];
83417
+ const container = isJSDocTemplateTag(declaration.parent) ? getJSDocHost(declaration.parent) : declaration.parent;
83418
+ if (!isFunctionLike(container)) continue;
83419
+ let reference;
83420
+ let hasInvalidReference = false;
83421
+ for (const paramDecl of container.parameters) {
83422
+ const typeNode = getEffectiveTypeAnnotationNode(paramDecl);
83423
+ if (!typeNode) continue;
83424
+ if (isTypeParameterReferenced(typeParam, typeNode)) {
83425
+ let candidateReference;
83426
+ if (isTypeReferenceNode(typeNode) && isReferenceToTypeParameter(typeParam, typeNode) && (candidateReference = getValidParameterReference(paramDecl, constraint))) {
83427
+ if (reference) {
83428
+ hasInvalidReference = true;
83429
+ break;
83430
+ }
83431
+ reference = candidateReference;
83432
+ } else {
83433
+ hasInvalidReference = true;
83434
+ break;
83435
+ }
83436
+ }
83437
+ }
83438
+ if (!hasInvalidReference && reference) {
83439
+ const symbol = getResolvedSymbol(reference);
83440
+ if (symbol !== unknownSymbol) narrowableParams.push([typeParam, symbol, reference]);
83441
+ }
83442
+ }
83443
+ }
83444
+ return narrowableParams;
83445
+ function getValidParameterReference(paramDecl, constraint) {
83446
+ if (!isIdentifier(paramDecl.name)) return;
83447
+ const isOptional = !!paramDecl.questionToken || isJSDocOptionalParameter(paramDecl);
83448
+ if (isOptional && !containsUndefinedType(constraint)) return;
83449
+ return paramDecl.name;
83450
+ }
83451
+ function isReferenceToTypeParameter(typeParam, node) {
83452
+ return getTypeFromTypeReference(node) === typeParam;
83453
+ }
83454
+ function isTypeParameterReferenced(typeParam, node) {
83455
+ return isReferenced(node);
83456
+ function isReferenced(node2) {
83457
+ if (isTypeReferenceNode(node2)) {
83458
+ return isReferenceToTypeParameter(typeParam, node2);
83459
+ }
83460
+ if (isTypeQueryNode(node2)) {
83461
+ return isTypeParameterPossiblyReferenced(typeParam, node2);
83462
+ }
83463
+ return !!forEachChild(node2, isReferenced);
83464
+ }
83465
+ }
83466
+ }
83467
+ function isNarrowableReturnType(returnType) {
83468
+ return isConditionalType(returnType) ? isNarrowableConditionalType(returnType) : !!(returnType.indexType.flags & 262144 /* TypeParameter */);
83469
+ }
83470
+ function isNarrowableConditionalType(type, mapper) {
83471
+ const typeArguments = mapper && map(type.root.outerTypeParameters, (t) => {
83472
+ const mapped = getMappedType(t, mapper);
83473
+ if (isNarrowingSubstitutionType(mapped)) {
83474
+ return mapped.baseType;
83475
+ }
83476
+ return mapped;
83477
+ });
83478
+ const id = `${type.id}:${getTypeListId(typeArguments)}`;
83479
+ let result = narrowableReturnTypeCache.get(id);
83480
+ if (result === void 0) {
83481
+ const nonNarrowingMapper = type.root.outerTypeParameters && typeArguments && createTypeMapper(type.root.outerTypeParameters, typeArguments);
83482
+ const instantiatedType = instantiateType(type, nonNarrowingMapper);
83483
+ result = isConditionalType(instantiatedType) && isNarrowableConditionalTypeWorker(instantiatedType);
83484
+ narrowableReturnTypeCache.set(id, result);
83485
+ }
83486
+ return result;
83487
+ }
83488
+ function isNarrowableConditionalTypeWorker(type) {
83489
+ if (!type.root.isDistributive) {
83490
+ return false;
83491
+ }
83492
+ if (type.root.inferTypeParameters) {
83493
+ return false;
83494
+ }
83495
+ if (!(type.checkType.flags & 262144 /* TypeParameter */)) {
83496
+ return false;
83497
+ }
83498
+ const constraintType = getConstraintOfTypeParameter(type.checkType);
83499
+ if (!constraintType || !(constraintType.flags & 1048576 /* Union */)) {
83500
+ return false;
83501
+ }
83502
+ if (!everyType(type.extendsType, (extendsType) => some(
83503
+ constraintType.types,
83504
+ (constraintType2) => isTypeIdenticalTo(constraintType2, extendsType)
83505
+ ))) {
83506
+ return false;
83507
+ }
83508
+ const trueType2 = getTrueTypeFromConditionalType(type);
83509
+ const isValidTrueType = isConditionalType(trueType2) ? isNarrowableConditionalType(trueType2) : true;
83510
+ if (!isValidTrueType) return false;
83511
+ const falseType2 = getFalseTypeFromConditionalType(type);
83512
+ const isValidFalseType = isConditionalType(falseType2) ? isNarrowableConditionalType(falseType2) : falseType2 === neverType;
83513
+ return isValidFalseType;
83514
+ }
83515
+ function isConditionalType(type) {
83516
+ return !!(type.flags & 16777216 /* Conditional */);
83517
+ }
83075
83518
  function checkWithStatement(node) {
83076
83519
  if (!checkGrammarStatementInAmbientContext(node)) {
83077
83520
  if (node.flags & 65536 /* AwaitContext */) {
@@ -93045,7 +93488,7 @@ function transformTypeScript(context) {
93045
93488
  return updated;
93046
93489
  }
93047
93490
  function visitParenthesizedExpression(node) {
93048
- const innerExpression = skipOuterExpressions(node.expression, ~(6 /* Assertions */ | 16 /* ExpressionsWithTypeArguments */));
93491
+ const innerExpression = skipOuterExpressions(node.expression, ~(38 /* Assertions */ | 16 /* ExpressionsWithTypeArguments */));
93049
93492
  if (isAssertionExpression(innerExpression) || isSatisfiesExpression(innerExpression)) {
93050
93493
  const expression = visitNode(node.expression, visitor, isExpression);
93051
93494
  Debug.assert(expression);