@typescript-deploys/pr-build 5.7.0-pr-57718-9 → 5.8.0-pr-52972-10

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/typescript.js CHANGED
@@ -2277,8 +2277,8 @@ __export(typescript_exports, {
2277
2277
  module.exports = __toCommonJS(typescript_exports);
2278
2278
 
2279
2279
  // src/compiler/corePublic.ts
2280
- var versionMajorMinor = "5.7";
2281
- var version = `${versionMajorMinor}.0-insiders.20241031`;
2280
+ var versionMajorMinor = "5.8";
2281
+ var version = `${versionMajorMinor}.0-insiders.20241127`;
2282
2282
  var Comparison = /* @__PURE__ */ ((Comparison3) => {
2283
2283
  Comparison3[Comparison3["LessThan"] = -1] = "LessThan";
2284
2284
  Comparison3[Comparison3["EqualTo"] = 0] = "EqualTo";
@@ -6531,6 +6531,7 @@ var ObjectFlags = /* @__PURE__ */ ((ObjectFlags3) => {
6531
6531
  ObjectFlags3[ObjectFlags3["IsGenericObjectType"] = 4194304] = "IsGenericObjectType";
6532
6532
  ObjectFlags3[ObjectFlags3["IsGenericIndexType"] = 8388608] = "IsGenericIndexType";
6533
6533
  ObjectFlags3[ObjectFlags3["IsGenericType"] = 12582912] = "IsGenericType";
6534
+ ObjectFlags3[ObjectFlags3["IsNarrowingType"] = 16777216] = "IsNarrowingType";
6534
6535
  ObjectFlags3[ObjectFlags3["ContainsIntersections"] = 16777216] = "ContainsIntersections";
6535
6536
  ObjectFlags3[ObjectFlags3["IsUnknownLikeUnionComputed"] = 33554432] = "IsUnknownLikeUnionComputed";
6536
6537
  ObjectFlags3[ObjectFlags3["IsUnknownLikeUnion"] = 67108864] = "IsUnknownLikeUnion";
@@ -7141,8 +7142,9 @@ var OuterExpressionKinds = /* @__PURE__ */ ((OuterExpressionKinds2) => {
7141
7142
  OuterExpressionKinds2[OuterExpressionKinds2["NonNullAssertions"] = 4] = "NonNullAssertions";
7142
7143
  OuterExpressionKinds2[OuterExpressionKinds2["PartiallyEmittedExpressions"] = 8] = "PartiallyEmittedExpressions";
7143
7144
  OuterExpressionKinds2[OuterExpressionKinds2["ExpressionsWithTypeArguments"] = 16] = "ExpressionsWithTypeArguments";
7144
- OuterExpressionKinds2[OuterExpressionKinds2["Assertions"] = 6] = "Assertions";
7145
- OuterExpressionKinds2[OuterExpressionKinds2["All"] = 31] = "All";
7145
+ OuterExpressionKinds2[OuterExpressionKinds2["Satisfies"] = 32] = "Satisfies";
7146
+ OuterExpressionKinds2[OuterExpressionKinds2["Assertions"] = 38] = "Assertions";
7147
+ OuterExpressionKinds2[OuterExpressionKinds2["All"] = 63] = "All";
7146
7148
  OuterExpressionKinds2[OuterExpressionKinds2["ExcludeJSDocTypeAssertion"] = -2147483648] = "ExcludeJSDocTypeAssertion";
7147
7149
  return OuterExpressionKinds2;
7148
7150
  })(OuterExpressionKinds || {});
@@ -18774,7 +18776,7 @@ function tryGetImportFromModuleSpecifier(node) {
18774
18776
  }
18775
18777
  }
18776
18778
  function shouldRewriteModuleSpecifier(specifier, compilerOptions) {
18777
- return !!compilerOptions.rewriteRelativeImportExtensions && pathIsRelative(specifier) && !isDeclarationFileName(specifier);
18779
+ return !!compilerOptions.rewriteRelativeImportExtensions && pathIsRelative(specifier) && !isDeclarationFileName(specifier) && hasTSFileExtension(specifier);
18778
18780
  }
18779
18781
  function getExternalModuleName(node) {
18780
18782
  switch (node.kind) {
@@ -26552,6 +26554,8 @@ function createNodeFactory(flags, baseFactory2) {
26552
26554
  node.colonToken = colonToken ?? createToken(59 /* ColonToken */);
26553
26555
  node.whenFalse = parenthesizerRules().parenthesizeBranchOfConditionalExpression(whenFalse);
26554
26556
  node.transformFlags |= propagateChildFlags(node.condition) | propagateChildFlags(node.questionToken) | propagateChildFlags(node.whenTrue) | propagateChildFlags(node.colonToken) | propagateChildFlags(node.whenFalse);
26557
+ node.flowNodeWhenFalse = void 0;
26558
+ node.flowNodeWhenTrue = void 0;
26555
26559
  return node;
26556
26560
  }
26557
26561
  function updateConditionalExpression(node, condition, questionToken, whenTrue, colonToken, whenFalse) {
@@ -28355,7 +28359,7 @@ function createNodeFactory(flags, baseFactory2) {
28355
28359
  function isIgnorableParen(node) {
28356
28360
  return isParenthesizedExpression(node) && nodeIsSynthesized(node) && nodeIsSynthesized(getSourceMapRange(node)) && nodeIsSynthesized(getCommentRange(node)) && !some(getSyntheticLeadingComments(node)) && !some(getSyntheticTrailingComments(node));
28357
28361
  }
28358
- function restoreOuterExpressions(outerExpression, innerExpression, kinds = 31 /* All */) {
28362
+ function restoreOuterExpressions(outerExpression, innerExpression, kinds = 63 /* All */) {
28359
28363
  if (outerExpression && isOuterExpression(outerExpression, kinds) && !isIgnorableParen(outerExpression)) {
28360
28364
  return updateOuterExpression(
28361
28365
  outerExpression,
@@ -28401,7 +28405,7 @@ function createNodeFactory(flags, baseFactory2) {
28401
28405
  }
28402
28406
  }
28403
28407
  function createCallBinding(expression, recordTempVariable, languageVersion, cacheIdentifiers = false) {
28404
- const callee = skipOuterExpressions(expression, 31 /* All */);
28408
+ const callee = skipOuterExpressions(expression, 63 /* All */);
28405
28409
  let thisArg;
28406
28410
  let target;
28407
28411
  if (isSuperProperty(callee)) {
@@ -31404,7 +31408,7 @@ function getJSDocTypeAssertionType(node) {
31404
31408
  Debug.assertIsDefined(type);
31405
31409
  return type;
31406
31410
  }
31407
- function isOuterExpression(node, kinds = 31 /* All */) {
31411
+ function isOuterExpression(node, kinds = 63 /* All */) {
31408
31412
  switch (node.kind) {
31409
31413
  case 217 /* ParenthesizedExpression */:
31410
31414
  if (kinds & -2147483648 /* ExcludeJSDocTypeAssertion */ && isJSDocTypeAssertion(node)) {
@@ -31413,8 +31417,9 @@ function isOuterExpression(node, kinds = 31 /* All */) {
31413
31417
  return (kinds & 1 /* Parentheses */) !== 0;
31414
31418
  case 216 /* TypeAssertionExpression */:
31415
31419
  case 234 /* AsExpression */:
31416
- case 238 /* SatisfiesExpression */:
31417
31420
  return (kinds & 2 /* TypeAssertions */) !== 0;
31421
+ case 238 /* SatisfiesExpression */:
31422
+ return (kinds & (2 /* TypeAssertions */ | 32 /* Satisfies */)) !== 0;
31418
31423
  case 233 /* ExpressionWithTypeArguments */:
31419
31424
  return (kinds & 16 /* ExpressionsWithTypeArguments */) !== 0;
31420
31425
  case 235 /* NonNullExpression */:
@@ -31424,13 +31429,13 @@ function isOuterExpression(node, kinds = 31 /* All */) {
31424
31429
  }
31425
31430
  return false;
31426
31431
  }
31427
- function skipOuterExpressions(node, kinds = 31 /* All */) {
31432
+ function skipOuterExpressions(node, kinds = 63 /* All */) {
31428
31433
  while (isOuterExpression(node, kinds)) {
31429
31434
  node = node.expression;
31430
31435
  }
31431
31436
  return node;
31432
31437
  }
31433
- function walkUpOuterExpressions(node, kinds = 31 /* All */) {
31438
+ function walkUpOuterExpressions(node, kinds = 63 /* All */) {
31434
31439
  let parent2 = node.parent;
31435
31440
  while (isOuterExpression(parent2, kinds)) {
31436
31441
  parent2 = parent2.parent;
@@ -40351,6 +40356,7 @@ var libEntries = [
40351
40356
  ["esnext.regexp", "lib.es2024.regexp.d.ts"],
40352
40357
  ["esnext.string", "lib.es2024.string.d.ts"],
40353
40358
  ["esnext.iterator", "lib.esnext.iterator.d.ts"],
40359
+ ["esnext.promise", "lib.esnext.promise.d.ts"],
40354
40360
  ["decorators", "lib.decorators.d.ts"],
40355
40361
  ["decorators.legacy", "lib.decorators.legacy.d.ts"]
40356
40362
  ];
@@ -46411,6 +46417,7 @@ function createBinder() {
46411
46417
  var preSwitchCaseFlow;
46412
46418
  var activeLabelList;
46413
46419
  var hasExplicitReturn;
46420
+ var inReturnPosition;
46414
46421
  var hasFlowEffects;
46415
46422
  var emitFlags;
46416
46423
  var inStrictMode;
@@ -46483,6 +46490,7 @@ function createBinder() {
46483
46490
  currentExceptionTarget = void 0;
46484
46491
  activeLabelList = void 0;
46485
46492
  hasExplicitReturn = false;
46493
+ inReturnPosition = false;
46486
46494
  hasFlowEffects = false;
46487
46495
  inAssignmentPattern = false;
46488
46496
  emitFlags = 0 /* None */;
@@ -46719,6 +46727,8 @@ function createBinder() {
46719
46727
  const saveContainer = container;
46720
46728
  const saveThisParentContainer = thisParentContainer;
46721
46729
  const savedBlockScopeContainer = blockScopeContainer;
46730
+ const savedInReturnPosition = inReturnPosition;
46731
+ if (node.kind === 219 /* ArrowFunction */ && node.body.kind !== 241 /* Block */) inReturnPosition = true;
46722
46732
  if (containerFlags & 1 /* IsContainer */) {
46723
46733
  if (node.kind !== 219 /* ArrowFunction */) {
46724
46734
  thisParentContainer = container;
@@ -46796,6 +46806,7 @@ function createBinder() {
46796
46806
  } else {
46797
46807
  bindChildren(node);
46798
46808
  }
46809
+ inReturnPosition = savedInReturnPosition;
46799
46810
  container = saveContainer;
46800
46811
  thisParentContainer = saveThisParentContainer;
46801
46812
  blockScopeContainer = savedBlockScopeContainer;
@@ -47247,7 +47258,10 @@ function createBinder() {
47247
47258
  currentFlow = finishFlowLabel(postIfLabel);
47248
47259
  }
47249
47260
  function bindReturnOrThrow(node) {
47261
+ const savedInReturnPosition = inReturnPosition;
47262
+ inReturnPosition = true;
47250
47263
  bind(node.expression);
47264
+ inReturnPosition = savedInReturnPosition;
47251
47265
  if (node.kind === 253 /* ReturnStatement */) {
47252
47266
  hasExplicitReturn = true;
47253
47267
  if (currentReturnTarget) {
@@ -47608,10 +47622,16 @@ function createBinder() {
47608
47622
  hasFlowEffects = false;
47609
47623
  bindCondition(node.condition, trueLabel, falseLabel);
47610
47624
  currentFlow = finishFlowLabel(trueLabel);
47625
+ if (inReturnPosition) {
47626
+ node.flowNodeWhenTrue = currentFlow;
47627
+ }
47611
47628
  bind(node.questionToken);
47612
47629
  bind(node.whenTrue);
47613
47630
  addAntecedent(postExpressionLabel, currentFlow);
47614
47631
  currentFlow = finishFlowLabel(falseLabel);
47632
+ if (inReturnPosition) {
47633
+ node.flowNodeWhenFalse = currentFlow;
47634
+ }
47615
47635
  bind(node.colonToken);
47616
47636
  bind(node.whenFalse);
47617
47637
  addAntecedent(postExpressionLabel, currentFlow);
@@ -50768,8 +50788,8 @@ function createTypeChecker(host) {
50768
50788
  writeSignature: (signature, enclosingDeclaration, flags, kind, writer) => {
50769
50789
  return signatureToString(signature, getParseTreeNode(enclosingDeclaration), flags, kind, writer);
50770
50790
  },
50771
- writeType: (type, enclosingDeclaration, flags, writer) => {
50772
- return typeToString(type, getParseTreeNode(enclosingDeclaration), flags, writer);
50791
+ writeType: (type, enclosingDeclaration, flags, writer, verbosityLevel, out) => {
50792
+ return typeToString(type, getParseTreeNode(enclosingDeclaration), flags, writer, verbosityLevel, out);
50773
50793
  },
50774
50794
  writeSymbol: (symbol, enclosingDeclaration, meaning, flags, writer) => {
50775
50795
  return symbolToString(symbol, getParseTreeNode(enclosingDeclaration), meaning, flags, writer);
@@ -51555,6 +51575,7 @@ function createTypeChecker(host) {
51555
51575
  [".jsx", ".jsx"],
51556
51576
  [".json", ".json"]
51557
51577
  ];
51578
+ var narrowableReturnTypeCache = /* @__PURE__ */ new Map();
51558
51579
  initializeTypeChecker();
51559
51580
  return checker;
51560
51581
  function isDefinitelyReferenceToGlobalSymbolObject(node) {
@@ -52418,9 +52439,9 @@ function createTypeChecker(host) {
52418
52439
  const containerKind = grandparent.parent.kind;
52419
52440
  if (containerKind === 264 /* InterfaceDeclaration */ && heritageKind === 96 /* ExtendsKeyword */) {
52420
52441
  error2(errorLocation, Diagnostics.An_interface_cannot_extend_a_primitive_type_like_0_It_can_only_extend_other_named_object_types, unescapeLeadingUnderscores(name));
52421
- } else if (containerKind === 263 /* ClassDeclaration */ && heritageKind === 96 /* ExtendsKeyword */) {
52442
+ } else if (isClassLike(grandparent.parent) && heritageKind === 96 /* ExtendsKeyword */) {
52422
52443
  error2(errorLocation, Diagnostics.A_class_cannot_extend_a_primitive_type_like_0_Classes_can_only_extend_constructable_values, unescapeLeadingUnderscores(name));
52423
- } else if (containerKind === 263 /* ClassDeclaration */ && heritageKind === 119 /* ImplementsKeyword */) {
52444
+ } else if (isClassLike(grandparent.parent) && heritageKind === 119 /* ImplementsKeyword */) {
52424
52445
  error2(errorLocation, Diagnostics.A_class_cannot_implement_a_primitive_type_like_0_It_can_only_implement_other_named_object_types, unescapeLeadingUnderscores(name));
52425
52446
  }
52426
52447
  } else {
@@ -54293,7 +54314,7 @@ function createTypeChecker(host) {
54293
54314
  const links = getSymbolLinks(symbol);
54294
54315
  const cache = links.accessibleChainCache || (links.accessibleChainCache = /* @__PURE__ */ new Map());
54295
54316
  const firstRelevantLocation = forEachSymbolTableInScope(enclosingDeclaration, (_, __, ___, node) => node);
54296
- const key = `${useOnlyExternalAliasing ? 0 : 1}|${firstRelevantLocation && getNodeId(firstRelevantLocation)}|${meaning}`;
54317
+ const key = `${useOnlyExternalAliasing ? 0 : 1}|${firstRelevantLocation ? getNodeId(firstRelevantLocation) : 0}|${meaning}`;
54297
54318
  if (cache.has(key)) {
54298
54319
  return cache.get(key);
54299
54320
  }
@@ -54690,14 +54711,18 @@ function createTypeChecker(host) {
54690
54711
  return writer2;
54691
54712
  }
54692
54713
  }
54693
- function typeToString(type, enclosingDeclaration, flags = 1048576 /* AllowUniqueESSymbolType */ | 16384 /* UseAliasDefinedOutsideCurrentScope */, writer = createTextWriter("")) {
54694
- const noTruncation = compilerOptions.noErrorTruncation || flags & 1 /* NoTruncation */;
54714
+ function typeToString(type, enclosingDeclaration, flags = 1048576 /* AllowUniqueESSymbolType */ | 16384 /* UseAliasDefinedOutsideCurrentScope */, writer = createTextWriter(""), verbosityLevel, out) {
54715
+ const noTruncation = compilerOptions.noErrorTruncation || flags & 1 /* NoTruncation */ || verbosityLevel !== void 0;
54695
54716
  const typeNode = nodeBuilder.typeToTypeNode(
54696
54717
  type,
54697
54718
  enclosingDeclaration,
54698
- toNodeBuilderFlags(flags) | 70221824 /* IgnoreErrors */ | (noTruncation ? 1 /* NoTruncation */ : 0 /* None */),
54719
+ toNodeBuilderFlags(flags) | 70221824 /* IgnoreErrors */ | (noTruncation ? 1 /* NoTruncation */ : 0),
54699
54720
  /*internalFlags*/
54700
- void 0
54721
+ void 0,
54722
+ /*tracker*/
54723
+ void 0,
54724
+ verbosityLevel,
54725
+ out
54701
54726
  );
54702
54727
  if (typeNode === void 0) return Debug.fail("should always get typenode");
54703
54728
  const printer = type !== unresolvedType ? createPrinterWithRemoveComments() : createPrinterWithDefaults();
@@ -54837,12 +54862,7 @@ function createTypeChecker(host) {
54837
54862
  enterNewScope(context, node) {
54838
54863
  if (isFunctionLike(node) || isJSDocSignature(node)) {
54839
54864
  const signature = getSignatureFromDeclaration(node);
54840
- const expandedParams = getExpandedParameters(
54841
- signature,
54842
- /*skipUnionExpanding*/
54843
- true
54844
- )[0];
54845
- return enterNewScope(context, node, expandedParams, signature.typeParameters);
54865
+ return enterNewScope(context, node, signature.parameters, signature.typeParameters);
54846
54866
  } else {
54847
54867
  const typeParameters = isConditionalTypeNode(node) ? getInferTypeParameters(node) : [getDeclaredTypeOfTypeParameter(getSymbolOfDeclaration(node.typeParameter))];
54848
54868
  return enterNewScope(
@@ -54929,31 +54949,127 @@ function createTypeChecker(host) {
54929
54949
  };
54930
54950
  return {
54931
54951
  syntacticBuilderResolver,
54932
- typeToTypeNode: (type, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(enclosingDeclaration, flags, internalFlags, tracker, (context) => typeToTypeNodeHelper(type, context)),
54933
- typePredicateToTypePredicateNode: (typePredicate, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(enclosingDeclaration, flags, internalFlags, tracker, (context) => typePredicateToTypePredicateNodeHelper(typePredicate, context)),
54934
- serializeTypeForExpression: (expr, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(enclosingDeclaration, flags, internalFlags, tracker, (context) => syntacticNodeBuilder.serializeTypeOfExpression(expr, context)),
54935
- serializeTypeForDeclaration: (declaration, symbol, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(enclosingDeclaration, flags, internalFlags, tracker, (context) => syntacticNodeBuilder.serializeTypeOfDeclaration(declaration, symbol, context)),
54936
- serializeReturnTypeForSignature: (signature, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(enclosingDeclaration, flags, internalFlags, tracker, (context) => syntacticNodeBuilder.serializeReturnTypeForSignature(signature, getSymbolOfDeclaration(signature), context)),
54937
- indexInfoToIndexSignatureDeclaration: (indexInfo, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(enclosingDeclaration, flags, internalFlags, tracker, (context) => indexInfoToIndexSignatureDeclarationHelper(
54938
- indexInfo,
54939
- context,
54940
- /*typeNode*/
54941
- void 0
54942
- )),
54943
- signatureToSignatureDeclaration: (signature, kind, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(enclosingDeclaration, flags, internalFlags, tracker, (context) => signatureToSignatureDeclarationHelper(signature, kind, context)),
54944
- symbolToEntityName: (symbol, meaning, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(enclosingDeclaration, flags, internalFlags, tracker, (context) => symbolToName(
54945
- symbol,
54946
- context,
54947
- meaning,
54948
- /*expectsIdentifier*/
54949
- false
54950
- )),
54951
- symbolToExpression: (symbol, meaning, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(enclosingDeclaration, flags, internalFlags, tracker, (context) => symbolToExpression(symbol, context, meaning)),
54952
- symbolToTypeParameterDeclarations: (symbol, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(enclosingDeclaration, flags, internalFlags, tracker, (context) => typeParametersToTypeParameterDeclarations(symbol, context)),
54953
- symbolToParameterDeclaration: (symbol, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(enclosingDeclaration, flags, internalFlags, tracker, (context) => symbolToParameterDeclaration(symbol, context)),
54954
- typeParameterToDeclaration: (parameter, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(enclosingDeclaration, flags, internalFlags, tracker, (context) => typeParameterToDeclaration(parameter, context)),
54955
- symbolTableToDeclarationStatements: (symbolTable, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(enclosingDeclaration, flags, internalFlags, tracker, (context) => symbolTableToDeclarationStatements(symbolTable, context)),
54956
- symbolToNode: (symbol, meaning, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(enclosingDeclaration, flags, internalFlags, tracker, (context) => symbolToNode(symbol, context, meaning))
54952
+ typeToTypeNode: (type, enclosingDeclaration, flags, internalFlags, tracker, verbosityLevel, out) => withContext2(enclosingDeclaration, flags, internalFlags, tracker, verbosityLevel, (context) => typeToTypeNodeHelper(type, context), out),
54953
+ typePredicateToTypePredicateNode: (typePredicate, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(
54954
+ enclosingDeclaration,
54955
+ flags,
54956
+ internalFlags,
54957
+ tracker,
54958
+ /*verbosityLevel*/
54959
+ void 0,
54960
+ (context) => typePredicateToTypePredicateNodeHelper(typePredicate, context)
54961
+ ),
54962
+ serializeTypeForDeclaration: (declaration, symbol, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(
54963
+ enclosingDeclaration,
54964
+ flags,
54965
+ internalFlags,
54966
+ tracker,
54967
+ /*verbosityLevel*/
54968
+ void 0,
54969
+ (context) => syntacticNodeBuilder.serializeTypeOfDeclaration(declaration, symbol, context)
54970
+ ),
54971
+ serializeReturnTypeForSignature: (signature, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(
54972
+ enclosingDeclaration,
54973
+ flags,
54974
+ internalFlags,
54975
+ tracker,
54976
+ /*verbosityLevel*/
54977
+ void 0,
54978
+ (context) => syntacticNodeBuilder.serializeReturnTypeForSignature(signature, getSymbolOfDeclaration(signature), context)
54979
+ ),
54980
+ serializeTypeForExpression: (expr, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(
54981
+ enclosingDeclaration,
54982
+ flags,
54983
+ internalFlags,
54984
+ tracker,
54985
+ /*verbosityLevel*/
54986
+ void 0,
54987
+ (context) => syntacticNodeBuilder.serializeTypeOfExpression(expr, context)
54988
+ ),
54989
+ indexInfoToIndexSignatureDeclaration: (indexInfo, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(
54990
+ enclosingDeclaration,
54991
+ flags,
54992
+ internalFlags,
54993
+ tracker,
54994
+ /*verbosityLevel*/
54995
+ void 0,
54996
+ (context) => indexInfoToIndexSignatureDeclarationHelper(
54997
+ indexInfo,
54998
+ context,
54999
+ /*typeNode*/
55000
+ void 0
55001
+ )
55002
+ ),
55003
+ signatureToSignatureDeclaration: (signature, kind, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(
55004
+ enclosingDeclaration,
55005
+ flags,
55006
+ internalFlags,
55007
+ tracker,
55008
+ /*verbosityLevel*/
55009
+ void 0,
55010
+ (context) => signatureToSignatureDeclarationHelper(signature, kind, context)
55011
+ ),
55012
+ symbolToEntityName: (symbol, meaning, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(
55013
+ enclosingDeclaration,
55014
+ flags,
55015
+ internalFlags,
55016
+ tracker,
55017
+ /*verbosityLevel*/
55018
+ void 0,
55019
+ (context) => symbolToName(
55020
+ symbol,
55021
+ context,
55022
+ meaning,
55023
+ /*expectsIdentifier*/
55024
+ false
55025
+ )
55026
+ ),
55027
+ symbolToExpression: (symbol, meaning, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(
55028
+ enclosingDeclaration,
55029
+ flags,
55030
+ internalFlags,
55031
+ tracker,
55032
+ /*verbosityLevel*/
55033
+ void 0,
55034
+ (context) => symbolToExpression(symbol, context, meaning)
55035
+ ),
55036
+ symbolToTypeParameterDeclarations: (symbol, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(
55037
+ enclosingDeclaration,
55038
+ flags,
55039
+ internalFlags,
55040
+ tracker,
55041
+ /*verbosityLevel*/
55042
+ void 0,
55043
+ (context) => typeParametersToTypeParameterDeclarations(symbol, context)
55044
+ ),
55045
+ symbolToParameterDeclaration: (symbol, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(
55046
+ enclosingDeclaration,
55047
+ flags,
55048
+ internalFlags,
55049
+ tracker,
55050
+ /*verbosityLevel*/
55051
+ void 0,
55052
+ (context) => symbolToParameterDeclaration(symbol, context)
55053
+ ),
55054
+ typeParameterToDeclaration: (parameter, enclosingDeclaration, flags, internalFlags, tracker, verbosityLevel) => withContext2(enclosingDeclaration, flags, internalFlags, tracker, verbosityLevel, (context) => typeParameterToDeclaration(parameter, context)),
55055
+ symbolTableToDeclarationStatements: (symbolTable, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(
55056
+ enclosingDeclaration,
55057
+ flags,
55058
+ internalFlags,
55059
+ tracker,
55060
+ /*verbosityLevel*/
55061
+ void 0,
55062
+ (context) => symbolTableToDeclarationStatements(symbolTable, context)
55063
+ ),
55064
+ symbolToNode: (symbol, meaning, enclosingDeclaration, flags, internalFlags, tracker) => withContext2(
55065
+ enclosingDeclaration,
55066
+ flags,
55067
+ internalFlags,
55068
+ tracker,
55069
+ /*verbosityLevel*/
55070
+ void 0,
55071
+ (context) => symbolToNode(symbol, context, meaning)
55072
+ )
54957
55073
  };
54958
55074
  function getTypeFromTypeNode2(context, node, noMappedTypes) {
54959
55075
  const type = getTypeFromTypeNodeWithoutContext(node);
@@ -54995,7 +55111,7 @@ function createTypeChecker(host) {
54995
55111
  }
54996
55112
  return symbolToExpression(symbol, context, meaning);
54997
55113
  }
54998
- function withContext2(enclosingDeclaration, flags, internalFlags, tracker, cb) {
55114
+ function withContext2(enclosingDeclaration, flags, internalFlags, tracker, verbosityLevel, cb, out) {
54999
55115
  const moduleResolverHost = (tracker == null ? void 0 : tracker.trackSymbol) ? tracker.moduleResolverHost : (internalFlags || 0 /* None */) & 4 /* DoNotIncludeSymbolChain */ ? createBasicNodeBuilderModuleSpecifierResolutionHost(host) : void 0;
55000
55116
  const context = {
55001
55117
  enclosingDeclaration,
@@ -55003,6 +55119,7 @@ function createTypeChecker(host) {
55003
55119
  flags: flags || 0 /* None */,
55004
55120
  internalFlags: internalFlags || 0 /* None */,
55005
55121
  tracker: void 0,
55122
+ unfoldDepth: verbosityLevel ?? -1,
55006
55123
  encounteredError: false,
55007
55124
  suppressReportInferenceFallback: false,
55008
55125
  reportedDiagnostic: false,
@@ -55024,13 +55141,18 @@ function createTypeChecker(host) {
55024
55141
  typeParameterNamesByText: void 0,
55025
55142
  typeParameterNamesByTextNextNameCount: void 0,
55026
55143
  enclosingSymbolTypes: /* @__PURE__ */ new Map(),
55027
- mapper: void 0
55144
+ mapper: void 0,
55145
+ depth: 0,
55146
+ couldUnfoldMore: false
55028
55147
  };
55029
55148
  context.tracker = new SymbolTrackerImpl(context, tracker, moduleResolverHost);
55030
55149
  const resultingNode = cb(context);
55031
55150
  if (context.truncating && context.flags & 1 /* NoTruncation */) {
55032
55151
  context.tracker.reportTruncationError();
55033
55152
  }
55153
+ if (out) {
55154
+ out.couldUnfoldMore = context.couldUnfoldMore;
55155
+ }
55034
55156
  return context.encounteredError ? void 0 : resultingNode;
55035
55157
  }
55036
55158
  function addSymbolTypeToContext(context, symbol, type) {
@@ -55049,16 +55171,36 @@ function createTypeChecker(host) {
55049
55171
  function saveRestoreFlags(context) {
55050
55172
  const flags = context.flags;
55051
55173
  const internalFlags = context.internalFlags;
55174
+ const depth = context.depth;
55052
55175
  return restore;
55053
55176
  function restore() {
55054
55177
  context.flags = flags;
55055
55178
  context.internalFlags = internalFlags;
55179
+ context.depth = depth;
55056
55180
  }
55057
55181
  }
55058
55182
  function checkTruncationLength(context) {
55059
55183
  if (context.truncating) return context.truncating;
55060
55184
  return context.truncating = context.approximateLength > (context.flags & 1 /* NoTruncation */ ? noTruncationMaximumTruncationLength : defaultMaximumTruncationLength);
55061
55185
  }
55186
+ function couldUnfoldType(type, context) {
55187
+ var _a;
55188
+ if ((_a = context.visitedTypes) == null ? void 0 : _a.has(type.id)) {
55189
+ return false;
55190
+ }
55191
+ return context.depth < context.unfoldDepth || context.depth === context.unfoldDepth && !context.couldUnfoldMore;
55192
+ }
55193
+ function canUnfoldType(type, context) {
55194
+ var _a;
55195
+ if ((_a = context.visitedTypes) == null ? void 0 : _a.has(type.id)) {
55196
+ return false;
55197
+ }
55198
+ const result = context.depth < context.unfoldDepth;
55199
+ if (!result) {
55200
+ context.couldUnfoldMore = true;
55201
+ }
55202
+ return result;
55203
+ }
55062
55204
  function typeToTypeNodeHelper(type, context) {
55063
55205
  const restoreFlags = saveRestoreFlags(context);
55064
55206
  const typeNode = typeToTypeNodeWorker(type, context);
@@ -55206,16 +55348,27 @@ function createTypeChecker(host) {
55206
55348
  return factory.createThisTypeNode();
55207
55349
  }
55208
55350
  if (!inTypeAlias && type.aliasSymbol && (context.flags & 16384 /* UseAliasDefinedOutsideCurrentScope */ || isTypeSymbolAccessible(type.aliasSymbol, context.enclosingDeclaration))) {
55209
- const typeArgumentNodes = mapToTypeNodes(type.aliasTypeArguments, context);
55210
- if (isReservedMemberName(type.aliasSymbol.escapedName) && !(type.aliasSymbol.flags & 32 /* Class */)) return factory.createTypeReferenceNode(factory.createIdentifier(""), typeArgumentNodes);
55211
- if (length(typeArgumentNodes) === 1 && type.aliasSymbol === globalArrayType.symbol) {
55212
- return factory.createArrayTypeNode(typeArgumentNodes[0]);
55351
+ if (!canUnfoldType(type, context)) {
55352
+ const typeArgumentNodes = mapToTypeNodes(type.aliasTypeArguments, context);
55353
+ if (isReservedMemberName(type.aliasSymbol.escapedName) && !(type.aliasSymbol.flags & 32 /* Class */)) return factory.createTypeReferenceNode(factory.createIdentifier(""), typeArgumentNodes);
55354
+ if (length(typeArgumentNodes) === 1 && type.aliasSymbol === globalArrayType.symbol) {
55355
+ return factory.createArrayTypeNode(typeArgumentNodes[0]);
55356
+ }
55357
+ return symbolToTypeNode(type.aliasSymbol, context, 788968 /* Type */, typeArgumentNodes);
55213
55358
  }
55214
- return symbolToTypeNode(type.aliasSymbol, context, 788968 /* Type */, typeArgumentNodes);
55359
+ context.depth += 1;
55215
55360
  }
55216
55361
  const objectFlags = getObjectFlags(type);
55217
55362
  if (objectFlags & 4 /* Reference */) {
55218
55363
  Debug.assert(!!(type.flags & 524288 /* Object */));
55364
+ if (canUnfoldType(type, context)) {
55365
+ context.depth += 1;
55366
+ return createAnonymousTypeNode(
55367
+ type,
55368
+ /*forceClassExpansion*/
55369
+ true
55370
+ );
55371
+ }
55219
55372
  return type.node ? visitAndTransformType(type, typeReferenceToTypeNode) : typeReferenceToTypeNode(type);
55220
55373
  }
55221
55374
  if (type.flags & 262144 /* TypeParameter */ || objectFlags & 3 /* ClassOrInterface */) {
@@ -55245,6 +55398,14 @@ function createTypeChecker(host) {
55245
55398
  void 0
55246
55399
  );
55247
55400
  }
55401
+ if (objectFlags & 3 /* ClassOrInterface */ && canUnfoldType(type, context)) {
55402
+ context.depth += 1;
55403
+ return createAnonymousTypeNode(
55404
+ type,
55405
+ /*forceClassExpansion*/
55406
+ true
55407
+ );
55408
+ }
55248
55409
  if (type.symbol) {
55249
55410
  return symbolToTypeNode(type.symbol, context, 788968 /* Type */);
55250
55411
  }
@@ -55448,7 +55609,7 @@ function createTypeChecker(host) {
55448
55609
  }
55449
55610
  return result;
55450
55611
  }
55451
- function createAnonymousTypeNode(type2) {
55612
+ function createAnonymousTypeNode(type2, forceClassExpansion = false) {
55452
55613
  var _a2, _b2;
55453
55614
  const typeId = type2.id;
55454
55615
  const symbol = type2.symbol;
@@ -55471,7 +55632,7 @@ function createTypeChecker(host) {
55471
55632
  const isInstanceType = isClassInstanceSide(type2) ? 788968 /* Type */ : 111551 /* Value */;
55472
55633
  if (isJSConstructor(symbol.valueDeclaration)) {
55473
55634
  return symbolToTypeNode(symbol, context, isInstanceType);
55474
- } else if (symbol.flags & 32 /* Class */ && !getBaseTypeVariableOfClass(symbol) && !(symbol.valueDeclaration && isClassLike(symbol.valueDeclaration) && context.flags & 2048 /* WriteClassExpressionAsTypeLiteral */ && (!isClassDeclaration(symbol.valueDeclaration) || isSymbolAccessible(
55635
+ } else if (symbol.flags & 32 /* Class */ && !forceClassExpansion && !getBaseTypeVariableOfClass(symbol) && !(symbol.valueDeclaration && isClassLike(symbol.valueDeclaration) && context.flags & 2048 /* WriteClassExpressionAsTypeLiteral */ && (!isClassDeclaration(symbol.valueDeclaration) || isSymbolAccessible(
55475
55636
  symbol,
55476
55637
  context.enclosingDeclaration,
55477
55638
  isInstanceType,
@@ -55515,7 +55676,7 @@ function createTypeChecker(host) {
55515
55676
  if (id && !context.symbolDepth) {
55516
55677
  context.symbolDepth = /* @__PURE__ */ new Map();
55517
55678
  }
55518
- const links = context.enclosingDeclaration && getNodeLinks(context.enclosingDeclaration);
55679
+ const links = context.unfoldDepth >= 0 ? void 0 : context.enclosingDeclaration && getNodeLinks(context.enclosingDeclaration);
55519
55680
  const key = `${getTypeId(type2)}|${context.flags}|${context.internalFlags}`;
55520
55681
  if (links) {
55521
55682
  links.serializedTypes || (links.serializedTypes = /* @__PURE__ */ new Map());
@@ -56430,7 +56591,7 @@ function createTypeChecker(host) {
56430
56591
  return factory.createTypeParameterDeclaration(modifiers, name, constraintNode, defaultParameterNode);
56431
56592
  }
56432
56593
  function typeToTypeNodeHelperWithPossibleReusableTypeNode(type, typeNode, context) {
56433
- return typeNode && getTypeFromTypeNode2(context, typeNode) === type && syntacticNodeBuilder.tryReuseExistingTypeNode(context, typeNode) || typeToTypeNodeHelper(type, context);
56594
+ return !couldUnfoldType(type, context) && typeNode && getTypeFromTypeNode2(context, typeNode) === type && syntacticNodeBuilder.tryReuseExistingTypeNode(context, typeNode) || typeToTypeNodeHelper(type, context);
56434
56595
  }
56435
56596
  function typeParameterToDeclaration(type, context, constraint = getConstraintOfTypeParameter(type)) {
56436
56597
  const constraintNode = constraint && typeToTypeNodeHelperWithPossibleReusableTypeNode(constraint, getConstraintDeclaration(type), context);
@@ -57064,7 +57225,7 @@ function createTypeChecker(host) {
57064
57225
  let result;
57065
57226
  const addUndefinedForParameter = declaration && (isParameter(declaration) || isJSDocParameterTag(declaration)) && requiresAddingImplicitUndefined(declaration, context.enclosingDeclaration);
57066
57227
  const decl = declaration ?? symbol.valueDeclaration ?? getDeclarationWithTypeAnnotation(symbol) ?? ((_a = symbol.declarations) == null ? void 0 : _a[0]);
57067
- if (decl) {
57228
+ if (!couldUnfoldType(type, context) && decl) {
57068
57229
  if (isAccessor(decl)) {
57069
57230
  result = syntacticNodeBuilder.serializeTypeOfAccessor(decl, symbol, context);
57070
57231
  } else if (hasInferredType(decl) && !nodeIsSynthesized(decl) && !(getObjectFlags(type) & 196608 /* RequiresWidening */)) {
@@ -59859,7 +60020,6 @@ function createTypeChecker(host) {
59859
60020
  const flags = 4 /* Property */ | (e.initializer ? 16777216 /* Optional */ : 0);
59860
60021
  const symbol = createSymbol(flags, text);
59861
60022
  symbol.links.type = getTypeFromBindingElement(e, includePatternInType, reportErrors2);
59862
- symbol.links.bindingElement = e;
59863
60023
  members.set(symbol.escapedName, symbol);
59864
60024
  });
59865
60025
  const result = createAnonymousType(
@@ -61786,12 +61946,20 @@ function createTypeChecker(host) {
61786
61946
  const indexInfos = indexInfo ? [createIndexInfo(stringType, inferReverseMappedType(indexInfo.type, type.mappedType, type.constraintType) || unknownType, readonlyMask && indexInfo.isReadonly)] : emptyArray;
61787
61947
  const members = createSymbolTable();
61788
61948
  const limitedConstraint = getLimitedConstraint(type);
61949
+ const nameType = getNameTypeFromMappedType(type.mappedType);
61789
61950
  for (const prop of getPropertiesOfType(type.source)) {
61790
- if (limitedConstraint) {
61951
+ if (limitedConstraint || nameType) {
61791
61952
  const propertyNameType = getLiteralTypeFromProperty(prop, 8576 /* StringOrNumberLiteralOrUnique */);
61792
- if (!isTypeAssignableTo(propertyNameType, limitedConstraint)) {
61953
+ if (limitedConstraint && !isTypeAssignableTo(propertyNameType, limitedConstraint)) {
61793
61954
  continue;
61794
61955
  }
61956
+ if (nameType) {
61957
+ const nameMapper = appendTypeMapping(type.mappedType.mapper, getTypeParameterFromMappedType(type.mappedType), propertyNameType);
61958
+ const instantiatedNameType = instantiateType(nameType, nameMapper);
61959
+ if (instantiatedNameType.flags & 131072 /* Never */) {
61960
+ continue;
61961
+ }
61962
+ }
61795
61963
  }
61796
61964
  const checkFlags = 8192 /* ReverseMapped */ | (readonlyMask && isReadonlySymbol(prop) ? 8 /* Readonly */ : 0);
61797
61965
  const inferredProp = createSymbol(4 /* Property */ | prop.flags & optionalMask, prop.escapedName, checkFlags);
@@ -63787,11 +63955,14 @@ function createTypeChecker(host) {
63787
63955
  function isNoInferType(type) {
63788
63956
  return !!(type.flags & 33554432 /* Substitution */ && type.constraint.flags & 2 /* Unknown */);
63789
63957
  }
63790
- function getSubstitutionType(baseType, constraint) {
63791
- return constraint.flags & 3 /* AnyOrUnknown */ || constraint === baseType || baseType.flags & 1 /* Any */ ? baseType : getOrCreateSubstitutionType(baseType, constraint);
63958
+ function isNarrowingSubstitutionType(type) {
63959
+ return !!(type.flags & 33554432 /* Substitution */ && type.objectFlags & 16777216 /* IsNarrowingType */);
63792
63960
  }
63793
- function getOrCreateSubstitutionType(baseType, constraint) {
63794
- const id = `${getTypeId(baseType)}>${getTypeId(constraint)}`;
63961
+ function getSubstitutionType(baseType, constraint, isNarrowed) {
63962
+ return constraint.flags & 3 /* AnyOrUnknown */ || constraint === baseType || baseType.flags & 1 /* Any */ ? baseType : getOrCreateSubstitutionType(baseType, constraint, isNarrowed);
63963
+ }
63964
+ function getOrCreateSubstitutionType(baseType, constraint, isNarrowed) {
63965
+ const id = `${getTypeId(baseType)}>${getTypeId(constraint)}${isNarrowed ? ">N" : ""}`;
63795
63966
  const cached = substitutionTypes.get(id);
63796
63967
  if (cached) {
63797
63968
  return cached;
@@ -63799,6 +63970,9 @@ function createTypeChecker(host) {
63799
63970
  const result = createType(33554432 /* Substitution */);
63800
63971
  result.baseType = baseType;
63801
63972
  result.constraint = constraint;
63973
+ if (isNarrowed) {
63974
+ result.objectFlags |= 16777216 /* IsNarrowingType */;
63975
+ }
63802
63976
  substitutionTypes.set(id, result);
63803
63977
  return result;
63804
63978
  }
@@ -66001,7 +66175,7 @@ function createTypeChecker(host) {
66001
66175
  function isDeferredType(type, checkTuples) {
66002
66176
  return isGenericType(type) || checkTuples && isTupleType(type) && some(getElementTypes(type), isGenericType);
66003
66177
  }
66004
- function getConditionalType(root, mapper, forConstraint, aliasSymbol, aliasTypeArguments) {
66178
+ function getConditionalType(root, mapper, forConstraint, aliasSymbol, aliasTypeArguments, forNarrowing) {
66005
66179
  let result;
66006
66180
  let extraTypes;
66007
66181
  let tailCount = 0;
@@ -66018,10 +66192,11 @@ function createTypeChecker(host) {
66018
66192
  if (checkType === wildcardType || extendsType === wildcardType) {
66019
66193
  return wildcardType;
66020
66194
  }
66195
+ const effectiveCheckType = forNarrowing && isNarrowingSubstitutionType(checkType) ? checkType.constraint : checkType;
66021
66196
  const checkTypeNode = skipTypeParentheses(root.node.checkType);
66022
66197
  const extendsTypeNode = skipTypeParentheses(root.node.extendsType);
66023
66198
  const checkTuples = isSimpleTupleType(checkTypeNode) && isSimpleTupleType(extendsTypeNode) && length(checkTypeNode.elements) === length(extendsTypeNode.elements);
66024
- const checkTypeDeferred = isDeferredType(checkType, checkTuples);
66199
+ const checkTypeDeferred = isDeferredType(effectiveCheckType, checkTuples);
66025
66200
  let combinedMapper;
66026
66201
  if (root.inferTypeParameters) {
66027
66202
  const context = createInferenceContext(
@@ -66040,8 +66215,8 @@ function createTypeChecker(host) {
66040
66215
  }
66041
66216
  const inferredExtendsType = combinedMapper ? instantiateType(root.extendsType, combinedMapper) : extendsType;
66042
66217
  if (!checkTypeDeferred && !isDeferredType(inferredExtendsType, checkTuples)) {
66043
- if (!(inferredExtendsType.flags & 3 /* AnyOrUnknown */) && (checkType.flags & 1 /* Any */ || !isTypeAssignableTo(getPermissiveInstantiation(checkType), getPermissiveInstantiation(inferredExtendsType)))) {
66044
- if (checkType.flags & 1 /* Any */ || forConstraint && !(inferredExtendsType.flags & 131072 /* Never */) && someType(getPermissiveInstantiation(inferredExtendsType), (t) => isTypeAssignableTo(t, getPermissiveInstantiation(checkType)))) {
66218
+ if (!(inferredExtendsType.flags & 3 /* AnyOrUnknown */) && (effectiveCheckType.flags & 1 /* Any */ || !isTypeAssignableTo(getPermissiveInstantiation(effectiveCheckType), getPermissiveInstantiation(inferredExtendsType)))) {
66219
+ if (effectiveCheckType.flags & 1 /* Any */ || forConstraint && !(inferredExtendsType.flags & 131072 /* Never */) && someType(getPermissiveInstantiation(inferredExtendsType), (t) => isTypeAssignableTo(t, getPermissiveInstantiation(effectiveCheckType)))) {
66045
66220
  (extraTypes || (extraTypes = [])).push(instantiateType(getTypeFromTypeNode(root.node.trueType), combinedMapper || mapper));
66046
66221
  }
66047
66222
  const falseType2 = getTypeFromTypeNode(root.node.falseType);
@@ -66058,7 +66233,7 @@ function createTypeChecker(host) {
66058
66233
  result = instantiateType(falseType2, mapper);
66059
66234
  break;
66060
66235
  }
66061
- if (inferredExtendsType.flags & 3 /* AnyOrUnknown */ || isTypeAssignableTo(getRestrictiveInstantiation(checkType), getRestrictiveInstantiation(inferredExtendsType))) {
66236
+ if (inferredExtendsType.flags & 3 /* AnyOrUnknown */ || isTypeAssignableTo(getRestrictiveInstantiation(effectiveCheckType), getRestrictiveInstantiation(inferredExtendsType))) {
66062
66237
  const trueType2 = getTypeFromTypeNode(root.node.trueType);
66063
66238
  const trueMapper = combinedMapper || mapper;
66064
66239
  if (canTailRecurse(trueType2, trueMapper)) {
@@ -67024,8 +67199,39 @@ function createTypeChecker(host) {
67024
67199
  if (!result) {
67025
67200
  const newMapper = createTypeMapper(root.outerTypeParameters, typeArguments);
67026
67201
  const checkType = root.checkType;
67027
- const distributionType = root.isDistributive ? getReducedType(getMappedType(checkType, newMapper)) : void 0;
67028
- 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);
67202
+ let distributionType = root.isDistributive ? getReducedType(getMappedType(checkType, newMapper)) : void 0;
67203
+ let narrowingBaseType;
67204
+ const forNarrowing = distributionType && isNarrowingSubstitutionType(distributionType) && isNarrowableConditionalType(type, mapper);
67205
+ if (forNarrowing) {
67206
+ narrowingBaseType = distributionType.baseType;
67207
+ distributionType = getReducedType(distributionType.constraint);
67208
+ }
67209
+ if (distributionType && checkType !== distributionType && distributionType.flags & (1048576 /* Union */ | 131072 /* Never */)) {
67210
+ if (narrowingBaseType) {
67211
+ result = mapTypeToIntersection(
67212
+ distributionType,
67213
+ (t) => getConditionalType(
67214
+ root,
67215
+ prependTypeMapping(checkType, getSubstitutionType(
67216
+ narrowingBaseType,
67217
+ t,
67218
+ /*isNarrowed*/
67219
+ true
67220
+ ), newMapper),
67221
+ forConstraint,
67222
+ /*aliasSymbol*/
67223
+ void 0,
67224
+ /*aliasTypeArguments*/
67225
+ void 0,
67226
+ forNarrowing
67227
+ )
67228
+ );
67229
+ } else {
67230
+ result = mapTypeWithAlias(distributionType, (t) => getConditionalType(root, prependTypeMapping(checkType, t, newMapper), forConstraint), aliasSymbol, aliasTypeArguments);
67231
+ }
67232
+ } else {
67233
+ result = getConditionalType(root, newMapper, forConstraint, aliasSymbol, aliasTypeArguments, forNarrowing);
67234
+ }
67029
67235
  root.instantiations.set(id, result);
67030
67236
  }
67031
67237
  return result;
@@ -68168,10 +68374,12 @@ function createTypeChecker(host) {
68168
68374
  function shouldNormalizeIntersection(type) {
68169
68375
  let hasInstantiable = false;
68170
68376
  let hasNullableOrEmpty = false;
68377
+ let hasSubstitution = false;
68171
68378
  for (const t of type.types) {
68172
68379
  hasInstantiable || (hasInstantiable = !!(t.flags & 465829888 /* Instantiable */));
68173
68380
  hasNullableOrEmpty || (hasNullableOrEmpty = !!(t.flags & 98304 /* Nullable */) || isEmptyAnonymousObjectType(t));
68174
- if (hasInstantiable && hasNullableOrEmpty) return true;
68381
+ hasSubstitution || (hasSubstitution = isNarrowingSubstitutionType(t));
68382
+ if (hasInstantiable && hasNullableOrEmpty || hasSubstitution) return true;
68175
68383
  }
68176
68384
  return false;
68177
68385
  }
@@ -72379,10 +72587,13 @@ function createTypeChecker(host) {
72379
72587
  if (isGenericMappedType(source) && isGenericMappedType(target)) {
72380
72588
  inferFromGenericMappedTypes(source, target);
72381
72589
  }
72382
- if (getObjectFlags(target) & 32 /* Mapped */ && !target.declaration.nameType) {
72383
- const constraintType = getConstraintTypeFromMappedType(target);
72384
- if (inferToMappedType(source, target, constraintType)) {
72385
- return;
72590
+ if (getObjectFlags(target) & 32 /* Mapped */) {
72591
+ const mappedType = target;
72592
+ if (getMappedTypeNameTypeKind(mappedType) !== 2 /* Remapping */) {
72593
+ const constraintType = getConstraintTypeFromMappedType(mappedType);
72594
+ if (inferToMappedType(source, mappedType, constraintType)) {
72595
+ return;
72596
+ }
72386
72597
  }
72387
72598
  }
72388
72599
  if (!typesDefinitelyUnrelated(source, target)) {
@@ -73330,6 +73541,18 @@ function createTypeChecker(host) {
73330
73541
  }
73331
73542
  return changed ? mappedTypes && getUnionType(mappedTypes, noReductions ? 0 /* None */ : 1 /* Literal */) : type;
73332
73543
  }
73544
+ function mapTypeToIntersection(type, mapper) {
73545
+ if (type.flags & 131072 /* Never */) {
73546
+ return type;
73547
+ }
73548
+ if (!(type.flags & 1048576 /* Union */)) {
73549
+ return mapper(type);
73550
+ }
73551
+ const origin = type.origin;
73552
+ const types = origin && origin.flags & 1048576 /* Union */ ? origin.types : type.types;
73553
+ const mappedTypes = types.map((t) => t.flags & 1048576 /* Union */ ? mapTypeToIntersection(t, mapper) : mapper(t));
73554
+ return getIntersectionType(mappedTypes);
73555
+ }
73333
73556
  function mapTypeWithAlias(type, mapper, aliasSymbol, aliasTypeArguments) {
73334
73557
  return type.flags & 1048576 /* Union */ && aliasSymbol ? getUnionType(map(type.types, mapper), 1 /* Literal */, aliasSymbol, aliasTypeArguments) : mapType(type, mapper);
73335
73558
  }
@@ -74912,11 +75135,11 @@ function createTypeChecker(host) {
74912
75135
  ));
74913
75136
  return contextualType && !isGenericType(contextualType);
74914
75137
  }
74915
- function getNarrowableTypeForReference(type, reference, checkMode) {
75138
+ function getNarrowableTypeForReference(type, reference, checkMode, forReturnTypeNarrowing) {
74916
75139
  if (isNoInferType(type)) {
74917
75140
  type = type.baseType;
74918
75141
  }
74919
- const substituteConstraints = !(checkMode && checkMode & 2 /* Inferential */) && someType(type, isGenericTypeWithUnionConstraint) && (isConstraintPosition(type, reference) || hasContextualTypeWithNoGenericTypes(reference, checkMode));
75142
+ const substituteConstraints = !(checkMode && checkMode & 2 /* Inferential */) && someType(type, isGenericTypeWithUnionConstraint) && (forReturnTypeNarrowing || isConstraintPosition(type, reference) || hasContextualTypeWithNoGenericTypes(reference, checkMode));
74920
75143
  return substituteConstraints ? mapType(type, getBaseConstraintOrType) : type;
74921
75144
  }
74922
75145
  function isExportOrExportExpression(location) {
@@ -75069,7 +75292,7 @@ function createTypeChecker(host) {
75069
75292
  jsxFactorySym = resolveName(
75070
75293
  jsxFactoryLocation,
75071
75294
  jsxFactoryNamespace,
75072
- compilerOptions.jsx === 1 /* Preserve */ ? 111551 /* Value */ & ~384 /* Enum */ : 111551 /* Value */,
75295
+ compilerOptions.jsx === 1 /* Preserve */ || compilerOptions.jsx === 3 /* ReactNative */ ? 111551 /* Value */ & ~384 /* Enum */ : 111551 /* Value */,
75073
75296
  jsxFactoryRefErr,
75074
75297
  /*isUse*/
75075
75298
  true
@@ -75088,7 +75311,7 @@ function createTypeChecker(host) {
75088
75311
  resolveName(
75089
75312
  jsxFactoryLocation,
75090
75313
  localJsxNamespace,
75091
- compilerOptions.jsx === 1 /* Preserve */ ? 111551 /* Value */ & ~384 /* Enum */ : 111551 /* Value */,
75314
+ compilerOptions.jsx === 1 /* Preserve */ || compilerOptions.jsx === 3 /* ReactNative */ ? 111551 /* Value */ & ~384 /* Enum */ : 111551 /* Value */,
75092
75315
  jsxFactoryRefErr,
75093
75316
  /*isUse*/
75094
75317
  true
@@ -76041,9 +76264,16 @@ function createTypeChecker(host) {
76041
76264
  function getContextualTypeForReturnExpression(node, contextFlags) {
76042
76265
  const func = getContainingFunction(node);
76043
76266
  if (func) {
76267
+ const functionFlags = getFunctionFlags(func);
76268
+ const links = getNodeLinks(node);
76269
+ if (links.contextualReturnType) {
76270
+ if (functionFlags & 2 /* Async */) {
76271
+ return getUnionType([links.contextualReturnType, createPromiseLikeType(links.contextualReturnType)]);
76272
+ }
76273
+ return links.contextualReturnType;
76274
+ }
76044
76275
  let contextualReturnType = getContextualReturnType(func, contextFlags);
76045
76276
  if (contextualReturnType) {
76046
- const functionFlags = getFunctionFlags(func);
76047
76277
  if (functionFlags & 1 /* Generator */) {
76048
76278
  const isAsyncGenerator = (functionFlags & 2 /* Async */) !== 0;
76049
76279
  if (contextualReturnType.flags & 1048576 /* Union */) {
@@ -76741,6 +76971,13 @@ function createTypeChecker(host) {
76741
76971
  if (index >= 0) {
76742
76972
  return contextualTypes[index];
76743
76973
  }
76974
+ const links = getNodeLinks(node);
76975
+ if (links.contextualReturnType) {
76976
+ if (node.flags & 65536 /* AwaitContext */) {
76977
+ return getUnionType([links.contextualReturnType, createPromiseLikeType(links.contextualReturnType)]);
76978
+ }
76979
+ return links.contextualReturnType;
76980
+ }
76744
76981
  const { parent: parent2 } = node;
76745
76982
  switch (parent2.kind) {
76746
76983
  case 260 /* VariableDeclaration */:
@@ -79417,8 +79654,8 @@ function createTypeChecker(host) {
79417
79654
  }
79418
79655
  }
79419
79656
  function getEffectiveCheckNode(argument) {
79420
- argument = skipParentheses(argument);
79421
- return isSatisfiesExpression(argument) ? skipParentheses(argument.expression) : argument;
79657
+ const flags = isInJSFile(argument) ? 1 /* Parentheses */ | 32 /* Satisfies */ | -2147483648 /* ExcludeJSDocTypeAssertion */ : 1 /* Parentheses */ | 32 /* Satisfies */;
79658
+ return skipOuterExpressions(argument, flags);
79422
79659
  }
79423
79660
  function getSignatureApplicabilityError(node, args, signature, relation, checkMode, reportErrors2, containingMessageChain, inferenceContext) {
79424
79661
  const errorOutputContainer = { errors: void 0, skipLogging: true };
@@ -79843,11 +80080,16 @@ function createTypeChecker(host) {
79843
80080
  if (!result) {
79844
80081
  result = chooseOverload(candidates, assignableRelation, isSingleNonGenericCandidate, signatureHelpTrailingComma);
79845
80082
  }
80083
+ const links = getNodeLinks(node);
80084
+ if (links.resolvedSignature !== resolvingSignature && !candidatesOutArray) {
80085
+ Debug.assert(links.resolvedSignature);
80086
+ return links.resolvedSignature;
80087
+ }
79846
80088
  if (result) {
79847
80089
  return result;
79848
80090
  }
79849
80091
  result = getCandidateForOverloadFailure(node, candidates, args, !!candidatesOutArray, checkMode);
79850
- getNodeLinks(node).resolvedSignature = result;
80092
+ links.resolvedSignature = result;
79851
80093
  if (reportErrors2) {
79852
80094
  if (!headMessage && isInstanceof) {
79853
80095
  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;
@@ -80612,7 +80854,7 @@ function createTypeChecker(host) {
80612
80854
  const jsxFactorySymbol = getJsxNamespaceContainerForImplicitImport(node) ?? resolveName(
80613
80855
  node,
80614
80856
  jsxFragmentFactoryName,
80615
- compilerOptions.jsx === 1 /* Preserve */ ? 111551 /* Value */ & ~384 /* Enum */ : 111551 /* Value */,
80857
+ compilerOptions.jsx === 1 /* Preserve */ || compilerOptions.jsx === 3 /* ReactNative */ ? 111551 /* Value */ & ~384 /* Enum */ : 111551 /* Value */,
80616
80858
  /*nameNotFoundMessage*/
80617
80859
  jsxFactoryRefErr,
80618
80860
  /*isUse*/
@@ -80731,12 +80973,9 @@ function createTypeChecker(host) {
80731
80973
  resolutionStart = resolutionTargets.length;
80732
80974
  }
80733
80975
  links.resolvedSignature = resolvingSignature;
80734
- let result = resolveSignature(node, candidatesOutArray, checkMode || 0 /* Normal */);
80976
+ const result = resolveSignature(node, candidatesOutArray, checkMode || 0 /* Normal */);
80735
80977
  resolutionStart = saveResolutionStart;
80736
80978
  if (result !== resolvingSignature) {
80737
- if (links.resolvedSignature !== resolvingSignature) {
80738
- result = links.resolvedSignature;
80739
- }
80740
80979
  links.resolvedSignature = flowLoopStart === flowLoopCount ? result : cached;
80741
80980
  }
80742
80981
  return result;
@@ -82264,7 +82503,7 @@ function createTypeChecker(host) {
82264
82503
  });
82265
82504
  }
82266
82505
  function checkIfExpressionRefinesParameter(func, expr, param, initType) {
82267
- const antecedent = expr.flowNode || expr.parent.kind === 253 /* ReturnStatement */ && expr.parent.flowNode || createFlowNode(
82506
+ const antecedent = canHaveFlowNode(expr) && expr.flowNode || expr.parent.kind === 253 /* ReturnStatement */ && expr.parent.flowNode || createFlowNode(
82268
82507
  2 /* Start */,
82269
82508
  /*node*/
82270
82509
  void 0,
@@ -82412,19 +82651,7 @@ function createTypeChecker(host) {
82412
82651
  const exprType = checkExpression(node.body);
82413
82652
  const returnOrPromisedType = returnType && unwrapReturnType(returnType, functionFlags);
82414
82653
  if (returnOrPromisedType) {
82415
- const effectiveCheckNode = getEffectiveCheckNode(node.body);
82416
- if ((functionFlags & 3 /* AsyncGenerator */) === 2 /* Async */) {
82417
- const awaitedType = checkAwaitedType(
82418
- exprType,
82419
- /*withAlias*/
82420
- false,
82421
- effectiveCheckNode,
82422
- Diagnostics.The_return_type_of_an_async_function_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member
82423
- );
82424
- checkTypeAssignableToAndOptionallyElaborate(awaitedType, returnOrPromisedType, effectiveCheckNode, effectiveCheckNode);
82425
- } else {
82426
- checkTypeAssignableToAndOptionallyElaborate(exprType, returnOrPromisedType, effectiveCheckNode, effectiveCheckNode);
82427
- }
82654
+ checkReturnExpression(node, returnOrPromisedType, node.body, node.body, exprType);
82428
82655
  }
82429
82656
  }
82430
82657
  }
@@ -82507,7 +82734,7 @@ function createTypeChecker(host) {
82507
82734
  return false;
82508
82735
  }
82509
82736
  function checkReferenceExpression(expr, invalidReferenceMessage, invalidOptionalChainMessage) {
82510
- const node = skipOuterExpressions(expr, 6 /* Assertions */ | 1 /* Parentheses */);
82737
+ const node = skipOuterExpressions(expr, 38 /* Assertions */ | 1 /* Parentheses */);
82511
82738
  if (node.kind !== 80 /* Identifier */ && !isAccessExpression(node)) {
82512
82739
  error2(expr, invalidReferenceMessage);
82513
82740
  return false;
@@ -83158,7 +83385,7 @@ function createTypeChecker(host) {
83158
83385
  if (isBinaryExpression(right) && (right.operatorToken.kind === 57 /* BarBarToken */ || right.operatorToken.kind === 56 /* AmpersandAmpersandToken */)) {
83159
83386
  grammarErrorOnNode(right, Diagnostics._0_and_1_operations_cannot_be_mixed_without_parentheses, tokenToString(right.operatorToken.kind), tokenToString(operatorToken.kind));
83160
83387
  }
83161
- const leftTarget = skipOuterExpressions(left, 31 /* All */);
83388
+ const leftTarget = skipOuterExpressions(left, 63 /* All */);
83162
83389
  const nullishSemantics = getSyntacticNullishnessSemantics(leftTarget);
83163
83390
  if (nullishSemantics !== 3 /* Sometimes */) {
83164
83391
  if (node.parent.kind === 226 /* BinaryExpression */) {
@@ -83178,7 +83405,9 @@ function createTypeChecker(host) {
83178
83405
  switch (node.kind) {
83179
83406
  case 223 /* AwaitExpression */:
83180
83407
  case 213 /* CallExpression */:
83408
+ case 215 /* TaggedTemplateExpression */:
83181
83409
  case 212 /* ElementAccessExpression */:
83410
+ case 236 /* MetaProperty */:
83182
83411
  case 214 /* NewExpression */:
83183
83412
  case 211 /* PropertyAccessExpression */:
83184
83413
  case 229 /* YieldExpression */:
@@ -83194,6 +83423,8 @@ function createTypeChecker(host) {
83194
83423
  case 56 /* AmpersandAmpersandToken */:
83195
83424
  case 77 /* AmpersandAmpersandEqualsToken */:
83196
83425
  return 3 /* Sometimes */;
83426
+ case 28 /* CommaToken */:
83427
+ return getSyntacticNullishnessSemantics(node.right);
83197
83428
  }
83198
83429
  return 2 /* Never */;
83199
83430
  case 227 /* ConditionalExpression */:
@@ -87646,7 +87877,6 @@ function createTypeChecker(host) {
87646
87877
  }
87647
87878
  const signature = getSignatureFromDeclaration(container);
87648
87879
  const returnType = getReturnTypeOfSignature(signature);
87649
- const functionFlags = getFunctionFlags(container);
87650
87880
  if (strictNullChecks || node.expression || returnType.flags & 131072 /* Never */) {
87651
87881
  const exprType = node.expression ? checkExpressionCached(node.expression) : undefinedType;
87652
87882
  if (container.kind === 178 /* SetAccessor */) {
@@ -87654,26 +87884,249 @@ function createTypeChecker(host) {
87654
87884
  error2(node, Diagnostics.Setters_cannot_return_a_value);
87655
87885
  }
87656
87886
  } else if (container.kind === 176 /* Constructor */) {
87657
- if (node.expression && !checkTypeAssignableToAndOptionallyElaborate(exprType, returnType, node, node.expression)) {
87887
+ const exprType2 = node.expression ? checkExpressionCached(node.expression) : undefinedType;
87888
+ if (node.expression && !checkTypeAssignableToAndOptionallyElaborate(exprType2, returnType, node, node.expression)) {
87658
87889
  error2(node, Diagnostics.Return_type_of_constructor_signature_must_be_assignable_to_the_instance_type_of_the_class);
87659
87890
  }
87660
87891
  } else if (getReturnTypeFromAnnotation(container)) {
87661
- const unwrappedReturnType = unwrapReturnType(returnType, functionFlags) ?? returnType;
87662
- const unwrappedExprType = functionFlags & 2 /* Async */ ? checkAwaitedType(
87663
- exprType,
87664
- /*withAlias*/
87665
- false,
87666
- node,
87667
- Diagnostics.The_return_type_of_an_async_function_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member
87668
- ) : exprType;
87669
- if (unwrappedReturnType) {
87670
- checkTypeAssignableToAndOptionallyElaborate(unwrappedExprType, unwrappedReturnType, node, node.expression);
87671
- }
87892
+ const unwrappedReturnType = unwrapReturnType(returnType, getFunctionFlags(container)) ?? returnType;
87893
+ checkReturnExpression(container, unwrappedReturnType, node, node.expression, exprType);
87672
87894
  }
87673
87895
  } else if (container.kind !== 176 /* Constructor */ && compilerOptions.noImplicitReturns && !isUnwrappedReturnTypeUndefinedVoidOrAny(container, returnType)) {
87674
87896
  error2(node, Diagnostics.Not_all_code_paths_return_a_value);
87675
87897
  }
87676
87898
  }
87899
+ function checkReturnExpression(container, unwrappedReturnType, node, expr, exprType, inConditionalExpression = false) {
87900
+ const excludeJSDocTypeAssertions = isInJSFile(node);
87901
+ const functionFlags = getFunctionFlags(container);
87902
+ if (expr) {
87903
+ const unwrappedExpr = skipParentheses(expr, excludeJSDocTypeAssertions);
87904
+ if (isConditionalExpression(unwrappedExpr)) {
87905
+ checkReturnExpression(
87906
+ container,
87907
+ unwrappedReturnType,
87908
+ node,
87909
+ unwrappedExpr.whenTrue,
87910
+ checkExpression(unwrappedExpr.whenTrue),
87911
+ /*inConditionalExpression*/
87912
+ true
87913
+ );
87914
+ checkReturnExpression(
87915
+ container,
87916
+ unwrappedReturnType,
87917
+ node,
87918
+ unwrappedExpr.whenFalse,
87919
+ checkExpression(unwrappedExpr.whenFalse),
87920
+ /*inConditionalExpression*/
87921
+ true
87922
+ );
87923
+ return;
87924
+ }
87925
+ }
87926
+ const inReturnStatement = node.kind === 253 /* ReturnStatement */;
87927
+ const unwrappedExprType = functionFlags & 2 /* Async */ ? checkAwaitedType(
87928
+ exprType,
87929
+ /*withAlias*/
87930
+ false,
87931
+ node,
87932
+ Diagnostics.The_return_type_of_an_async_function_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member
87933
+ ) : exprType;
87934
+ const effectiveExpr = expr && getEffectiveCheckNode(expr);
87935
+ const errorNode = inReturnStatement && !inConditionalExpression ? node : effectiveExpr;
87936
+ if (!(unwrappedReturnType.flags & (8388608 /* IndexedAccess */ | 16777216 /* Conditional */)) || !couldContainTypeVariables(unwrappedReturnType)) {
87937
+ checkTypeAssignableToAndOptionallyElaborate(unwrappedExprType, unwrappedReturnType, errorNode, effectiveExpr);
87938
+ return;
87939
+ }
87940
+ if (checkTypeAssignableTo(
87941
+ unwrappedExprType,
87942
+ unwrappedReturnType,
87943
+ /*errorNode*/
87944
+ void 0
87945
+ )) {
87946
+ return;
87947
+ }
87948
+ let narrowPosition = node;
87949
+ let narrowFlowNode = inReturnStatement && node.flowNode;
87950
+ if (expr && isConditionalExpression(expr.parent)) {
87951
+ narrowFlowNode = expr.parent.whenTrue === expr ? expr.parent.flowNodeWhenTrue : expr.parent.flowNodeWhenFalse;
87952
+ narrowPosition = expr;
87953
+ }
87954
+ if (!narrowFlowNode) {
87955
+ checkTypeAssignableToAndOptionallyElaborate(unwrappedExprType, unwrappedReturnType, errorNode, effectiveExpr);
87956
+ return;
87957
+ }
87958
+ const allTypeParameters = appendTypeParameters(getOuterTypeParameters(
87959
+ container,
87960
+ /*includeThisTypes*/
87961
+ false
87962
+ ), getEffectiveTypeParameterDeclarations(container));
87963
+ const narrowableTypeParameters = allTypeParameters && getNarrowableTypeParameters(allTypeParameters);
87964
+ if (!narrowableTypeParameters || !narrowableTypeParameters.length || !isNarrowableReturnType(unwrappedReturnType)) {
87965
+ checkTypeAssignableToAndOptionallyElaborate(unwrappedExprType, unwrappedReturnType, errorNode, effectiveExpr);
87966
+ return;
87967
+ }
87968
+ const narrowedTypeParameters = [];
87969
+ const narrowedTypes = [];
87970
+ for (const [typeParam, symbol, reference] of narrowableTypeParameters) {
87971
+ const narrowReference = factory.cloneNode(reference);
87972
+ narrowReference.id = void 0;
87973
+ getNodeLinks(narrowReference).resolvedSymbol = symbol;
87974
+ setParent(narrowReference, narrowPosition.parent);
87975
+ narrowReference.flowNode = narrowFlowNode;
87976
+ const initialType = getNarrowableTypeForReference(
87977
+ typeParam,
87978
+ narrowReference,
87979
+ /*checkMode*/
87980
+ void 0,
87981
+ /*forReturnTypeNarrowing*/
87982
+ true
87983
+ );
87984
+ if (initialType === typeParam) {
87985
+ continue;
87986
+ }
87987
+ const flowType = getFlowTypeOfReference(narrowReference, initialType);
87988
+ const exprType2 = getTypeFromFlowType(flowType);
87989
+ if (exprType2.flags & 3 /* AnyOrUnknown */ || isErrorType(exprType2) || exprType2 === typeParam || exprType2 === mapType(typeParam, getBaseConstraintOrType)) {
87990
+ continue;
87991
+ }
87992
+ const narrowedType = getSubstitutionType(
87993
+ typeParam,
87994
+ exprType2,
87995
+ /*isNarrowed*/
87996
+ true
87997
+ );
87998
+ narrowedTypeParameters.push(typeParam);
87999
+ narrowedTypes.push(narrowedType);
88000
+ }
88001
+ const narrowMapper = createTypeMapper(narrowedTypeParameters, narrowedTypes);
88002
+ const narrowedReturnType = instantiateType(
88003
+ unwrappedReturnType,
88004
+ narrowMapper
88005
+ );
88006
+ if (expr) {
88007
+ const links = getNodeLinks(expr);
88008
+ if (!links.contextualReturnType) {
88009
+ links.contextualReturnType = narrowedReturnType;
88010
+ }
88011
+ }
88012
+ const narrowedExprType = expr ? checkExpression(expr) : undefinedType;
88013
+ const narrowedUnwrappedExprType = functionFlags & 2 /* Async */ ? checkAwaitedType(
88014
+ narrowedExprType,
88015
+ /*withAlias*/
88016
+ false,
88017
+ node,
88018
+ Diagnostics.The_return_type_of_an_async_function_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member
88019
+ ) : narrowedExprType;
88020
+ checkTypeAssignableToAndOptionallyElaborate(narrowedUnwrappedExprType, narrowedReturnType, errorNode, effectiveExpr);
88021
+ }
88022
+ function getNarrowableTypeParameters(candidates) {
88023
+ const narrowableParams = [];
88024
+ for (const typeParam of candidates) {
88025
+ const constraint = getConstraintOfTypeParameter(typeParam);
88026
+ if (!constraint || !(constraint.flags & 1048576 /* Union */)) continue;
88027
+ if (typeParam.symbol && typeParam.symbol.declarations && typeParam.symbol.declarations.length === 1) {
88028
+ const declaration = typeParam.symbol.declarations[0];
88029
+ const container = isJSDocTemplateTag(declaration.parent) ? getJSDocHost(declaration.parent) : declaration.parent;
88030
+ if (!isFunctionLike(container)) continue;
88031
+ let reference;
88032
+ let hasInvalidReference = false;
88033
+ for (const paramDecl of container.parameters) {
88034
+ const typeNode = getEffectiveTypeAnnotationNode(paramDecl);
88035
+ if (!typeNode) continue;
88036
+ if (isTypeParameterReferenced(typeParam, typeNode)) {
88037
+ let candidateReference;
88038
+ if (isTypeReferenceNode(typeNode) && isReferenceToTypeParameter(typeParam, typeNode) && (candidateReference = getValidParameterReference(paramDecl, constraint))) {
88039
+ if (reference) {
88040
+ hasInvalidReference = true;
88041
+ break;
88042
+ }
88043
+ reference = candidateReference;
88044
+ } else {
88045
+ hasInvalidReference = true;
88046
+ break;
88047
+ }
88048
+ }
88049
+ }
88050
+ if (!hasInvalidReference && reference) {
88051
+ const symbol = getResolvedSymbol(reference);
88052
+ if (symbol !== unknownSymbol) narrowableParams.push([typeParam, symbol, reference]);
88053
+ }
88054
+ }
88055
+ }
88056
+ return narrowableParams;
88057
+ function getValidParameterReference(paramDecl, constraint) {
88058
+ if (!isIdentifier(paramDecl.name)) return;
88059
+ const isOptional = !!paramDecl.questionToken || isJSDocOptionalParameter(paramDecl);
88060
+ if (isOptional && !containsUndefinedType(constraint)) return;
88061
+ return paramDecl.name;
88062
+ }
88063
+ function isReferenceToTypeParameter(typeParam, node) {
88064
+ return getTypeFromTypeReference(node) === typeParam;
88065
+ }
88066
+ function isTypeParameterReferenced(typeParam, node) {
88067
+ return isReferenced(node);
88068
+ function isReferenced(node2) {
88069
+ if (isTypeReferenceNode(node2)) {
88070
+ return isReferenceToTypeParameter(typeParam, node2);
88071
+ }
88072
+ if (isTypeQueryNode(node2)) {
88073
+ return isTypeParameterPossiblyReferenced(typeParam, node2);
88074
+ }
88075
+ return !!forEachChild(node2, isReferenced);
88076
+ }
88077
+ }
88078
+ }
88079
+ function isNarrowableReturnType(returnType) {
88080
+ return isConditionalType(returnType) ? isNarrowableConditionalType(returnType) : !!(returnType.indexType.flags & 262144 /* TypeParameter */);
88081
+ }
88082
+ function isNarrowableConditionalType(type, mapper) {
88083
+ const typeArguments = mapper && map(type.root.outerTypeParameters, (t) => {
88084
+ const mapped = getMappedType(t, mapper);
88085
+ if (isNarrowingSubstitutionType(mapped)) {
88086
+ return mapped.baseType;
88087
+ }
88088
+ return mapped;
88089
+ });
88090
+ const id = `${type.id}:${getTypeListId(typeArguments)}`;
88091
+ let result = narrowableReturnTypeCache.get(id);
88092
+ if (result === void 0) {
88093
+ const nonNarrowingMapper = type.root.outerTypeParameters && typeArguments && createTypeMapper(type.root.outerTypeParameters, typeArguments);
88094
+ const instantiatedType = instantiateType(type, nonNarrowingMapper);
88095
+ result = isConditionalType(instantiatedType) && isNarrowableConditionalTypeWorker(instantiatedType);
88096
+ narrowableReturnTypeCache.set(id, result);
88097
+ }
88098
+ return result;
88099
+ }
88100
+ function isNarrowableConditionalTypeWorker(type) {
88101
+ if (!type.root.isDistributive) {
88102
+ return false;
88103
+ }
88104
+ if (type.root.inferTypeParameters) {
88105
+ return false;
88106
+ }
88107
+ if (!(type.checkType.flags & 262144 /* TypeParameter */)) {
88108
+ return false;
88109
+ }
88110
+ const constraintType = getConstraintOfTypeParameter(type.checkType);
88111
+ if (!constraintType || !(constraintType.flags & 1048576 /* Union */)) {
88112
+ return false;
88113
+ }
88114
+ if (!everyType(type.extendsType, (extendsType) => some(
88115
+ constraintType.types,
88116
+ (constraintType2) => isTypeIdenticalTo(constraintType2, extendsType)
88117
+ ))) {
88118
+ return false;
88119
+ }
88120
+ const trueType2 = getTrueTypeFromConditionalType(type);
88121
+ const isValidTrueType = isConditionalType(trueType2) ? isNarrowableConditionalType(trueType2) : true;
88122
+ if (!isValidTrueType) return false;
88123
+ const falseType2 = getFalseTypeFromConditionalType(type);
88124
+ const isValidFalseType = isConditionalType(falseType2) ? isNarrowableConditionalType(falseType2) : falseType2 === neverType;
88125
+ return isValidFalseType;
88126
+ }
88127
+ function isConditionalType(type) {
88128
+ return !!(type.flags & 16777216 /* Conditional */);
88129
+ }
87677
88130
  function checkWithStatement(node) {
87678
88131
  if (!checkGrammarStatementInAmbientContext(node)) {
87679
88132
  if (node.flags & 65536 /* AwaitContext */) {
@@ -97829,7 +98282,7 @@ function transformTypeScript(context) {
97829
98282
  return updated;
97830
98283
  }
97831
98284
  function visitParenthesizedExpression(node) {
97832
- const innerExpression = skipOuterExpressions(node.expression, ~(6 /* Assertions */ | 16 /* ExpressionsWithTypeArguments */));
98285
+ const innerExpression = skipOuterExpressions(node.expression, ~(38 /* Assertions */ | 16 /* ExpressionsWithTypeArguments */));
97833
98286
  if (isAssertionExpression(innerExpression) || isSatisfiesExpression(innerExpression)) {
97834
98287
  const expression = visitNode(node.expression, visitor, isExpression);
97835
98288
  Debug.assert(expression);
@@ -136959,18 +137412,21 @@ function createSyntacticTypeNodeBuilder(options, resolver) {
136959
137412
  return failed;
136960
137413
  }
136961
137414
  function typeFromFunctionLikeExpression(fnNode, context) {
136962
- const oldNoInferenceFallback = context.noInferenceFallback;
136963
- context.noInferenceFallback = true;
136964
- createReturnFromSignature(
137415
+ const returnType = createReturnFromSignature(
136965
137416
  fnNode,
136966
137417
  /*symbol*/
136967
137418
  void 0,
136968
137419
  context
136969
137420
  );
136970
- reuseTypeParameters(fnNode.typeParameters, context);
136971
- fnNode.parameters.map((p) => ensureParameter(p, context));
136972
- context.noInferenceFallback = oldNoInferenceFallback;
136973
- return notImplemented2;
137421
+ const typeParameters = reuseTypeParameters(fnNode.typeParameters, context);
137422
+ const parameters = fnNode.parameters.map((p) => ensureParameter(p, context));
137423
+ return syntacticResult(
137424
+ factory.createFunctionTypeNode(
137425
+ typeParameters,
137426
+ parameters,
137427
+ returnType
137428
+ )
137429
+ );
136974
137430
  }
136975
137431
  function canGetTypeFromArrayLiteral(arrayLiteral, context, isConstContext) {
136976
137432
  if (!isConstContext) {
@@ -139817,9 +140273,9 @@ function mapToDisplayParts(writeDisplayParts) {
139817
140273
  displayPartWriter.clear();
139818
140274
  }
139819
140275
  }
139820
- function typeToDisplayParts(typechecker, type, enclosingDeclaration, flags = 0 /* None */) {
140276
+ function typeToDisplayParts(typechecker, type, enclosingDeclaration, flags = 0 /* None */, verbosityLevel, out) {
139821
140277
  return mapToDisplayParts((writer) => {
139822
- typechecker.writeType(type, enclosingDeclaration, flags | 1024 /* MultilineObjectLiterals */ | 16384 /* UseAliasDefinedOutsideCurrentScope */, writer);
140278
+ typechecker.writeType(type, enclosingDeclaration, flags | 1024 /* MultilineObjectLiterals */ | 16384 /* UseAliasDefinedOutsideCurrentScope */, writer, verbosityLevel, out);
139823
140279
  });
139824
140280
  }
139825
140281
  function symbolToDisplayParts(typeChecker, symbol, enclosingDeclaration, meaning, flags = 0 /* None */) {
@@ -140526,7 +140982,7 @@ function moduleSymbolToValidIdentifier(moduleSymbol, target, forceCapitalize) {
140526
140982
  return moduleSpecifierToValidIdentifier(removeFileExtension(stripQuotes(moduleSymbol.name)), target, forceCapitalize);
140527
140983
  }
140528
140984
  function moduleSpecifierToValidIdentifier(moduleSpecifier, target, forceCapitalize) {
140529
- const baseName = getBaseFileName(removeSuffix(moduleSpecifier, "/index"));
140985
+ const baseName = getBaseFileName(removeSuffix(removeFileExtension(moduleSpecifier), "/index"));
140530
140986
  let res = "";
140531
140987
  let lastCharWasValid = true;
140532
140988
  const firstCharCode = baseName.charCodeAt(0);
@@ -140738,6 +141194,7 @@ var ExportKind = /* @__PURE__ */ ((ExportKind3) => {
140738
141194
  ExportKind3[ExportKind3["Default"] = 1] = "Default";
140739
141195
  ExportKind3[ExportKind3["ExportEquals"] = 2] = "ExportEquals";
140740
141196
  ExportKind3[ExportKind3["UMD"] = 3] = "UMD";
141197
+ ExportKind3[ExportKind3["Module"] = 4] = "Module";
140741
141198
  return ExportKind3;
140742
141199
  })(ExportKind || {});
140743
141200
  function createCacheableExportInfoMap(host) {
@@ -146430,23 +146887,22 @@ function getUsageInfo(oldFile, toMove, checker, existingTargetLocals = /* @__PUR
146430
146887
  const unusedImportsFromOldFile = /* @__PURE__ */ new Set();
146431
146888
  for (const statement of toMove) {
146432
146889
  forEachReference(statement, checker, enclosingRange, (symbol, isValidTypeOnlyUseSite) => {
146433
- if (!symbol.declarations || isGlobalType(checker, symbol)) {
146890
+ if (!symbol.declarations) {
146434
146891
  return;
146435
146892
  }
146436
146893
  if (existingTargetLocals.has(skipAlias(symbol, checker))) {
146437
146894
  unusedImportsFromOldFile.add(symbol);
146438
146895
  return;
146439
146896
  }
146440
- for (const decl of symbol.declarations) {
146441
- if (isInImport(decl)) {
146442
- const prevIsTypeOnly = oldImportsNeededByTargetFile.get(symbol);
146443
- oldImportsNeededByTargetFile.set(symbol, [
146444
- prevIsTypeOnly === void 0 ? isValidTypeOnlyUseSite : prevIsTypeOnly && isValidTypeOnlyUseSite,
146445
- tryCast(decl, (d) => isImportSpecifier(d) || isImportClause(d) || isNamespaceImport(d) || isImportEqualsDeclaration(d) || isBindingElement(d) || isVariableDeclaration(d))
146446
- ]);
146447
- } else if (isTopLevelDeclaration(decl) && sourceFileOfTopLevelDeclaration(decl) === oldFile && !movedSymbols.has(symbol)) {
146448
- targetFileImportsFromOldFile.set(symbol, isValidTypeOnlyUseSite);
146449
- }
146897
+ const importedDeclaration = find(symbol.declarations, isInImport);
146898
+ if (importedDeclaration) {
146899
+ const prevIsTypeOnly = oldImportsNeededByTargetFile.get(symbol);
146900
+ oldImportsNeededByTargetFile.set(symbol, [
146901
+ prevIsTypeOnly === void 0 ? isValidTypeOnlyUseSite : prevIsTypeOnly && isValidTypeOnlyUseSite,
146902
+ tryCast(importedDeclaration, (d) => isImportSpecifier(d) || isImportClause(d) || isNamespaceImport(d) || isImportEqualsDeclaration(d) || isBindingElement(d) || isVariableDeclaration(d))
146903
+ ]);
146904
+ } else if (!movedSymbols.has(symbol) && every(symbol.declarations, (decl) => isTopLevelDeclaration(decl) && sourceFileOfTopLevelDeclaration(decl) === oldFile)) {
146905
+ targetFileImportsFromOldFile.set(symbol, isValidTypeOnlyUseSite);
146450
146906
  }
146451
146907
  });
146452
146908
  }
@@ -146480,16 +146936,6 @@ function getUsageInfo(oldFile, toMove, checker, existingTargetLocals = /* @__PUR
146480
146936
  return !!jsxNamespaceSymbol2 && some(jsxNamespaceSymbol2.declarations, isInImport) ? jsxNamespaceSymbol2 : void 0;
146481
146937
  }
146482
146938
  }
146483
- function isGlobalType(checker, symbol) {
146484
- return !!checker.resolveName(
146485
- symbol.name,
146486
- /*location*/
146487
- void 0,
146488
- 788968 /* Type */,
146489
- /*excludeGlobals*/
146490
- false
146491
- );
146492
- }
146493
146939
  function makeUniqueFilename(proposedFilename, extension, inDirectory, host) {
146494
146940
  let newFilename = proposedFilename;
146495
146941
  for (let i = 1; ; i++) {
@@ -146708,6 +147154,9 @@ function addTargetFileImports(oldFile, importsToCopy, targetFileImportsFromOldFi
146708
147154
  const targetSymbol = skipAlias(symbol, checker);
146709
147155
  if (checker.isUnknownSymbol(targetSymbol)) {
146710
147156
  importAdder.addVerbatimImport(Debug.checkDefined(declaration ?? findAncestor((_a = symbol.declarations) == null ? void 0 : _a[0], isAnyImportOrRequireStatement)));
147157
+ } else if (targetSymbol.parent === void 0) {
147158
+ Debug.assert(declaration !== void 0, "expected module symbol to have a declaration");
147159
+ importAdder.addImportForModuleSymbol(symbol, isValidTypeOnlyUseSite, declaration);
146711
147160
  } else {
146712
147161
  importAdder.addImportFromExportedSymbol(targetSymbol, isValidTypeOnlyUseSite, declaration);
146713
147162
  }
@@ -151309,8 +151758,7 @@ var invalidOperationsInPartialSemanticMode = [
151309
151758
  "provideCallHierarchyOutgoingCalls",
151310
151759
  "provideInlayHints",
151311
151760
  "getSupportedCodeFixes",
151312
- "getPasteEdits",
151313
- "getImports"
151761
+ "getPasteEdits"
151314
151762
  ];
151315
151763
  var invalidOperationsInSyntacticMode = [
151316
151764
  ...invalidOperationsInPartialSemanticMode,
@@ -151792,7 +152240,7 @@ function createLanguageService(host, documentRegistry = createDocumentRegistry(h
151792
152240
  synchronizeHostData();
151793
152241
  return ts_Completions_exports.getCompletionEntrySymbol(program, log, getValidSourceFile(fileName), position, { name, source }, host, preferences);
151794
152242
  }
151795
- function getQuickInfoAtPosition(fileName, position) {
152243
+ function getQuickInfoAtPosition(fileName, position, verbosityLevel) {
151796
152244
  synchronizeHostData();
151797
152245
  const sourceFile = getValidSourceFile(fileName);
151798
152246
  const node = getTouchingPropertyName(sourceFile, position);
@@ -151808,19 +152256,41 @@ function createLanguageService(host, documentRegistry = createDocumentRegistry(h
151808
152256
  kind: "" /* unknown */,
151809
152257
  kindModifiers: "" /* none */,
151810
152258
  textSpan: createTextSpanFromNode(nodeForQuickInfo, sourceFile),
151811
- displayParts: typeChecker.runWithCancellationToken(cancellationToken, (typeChecker2) => typeToDisplayParts(typeChecker2, type, getContainerNode(nodeForQuickInfo))),
152259
+ displayParts: typeChecker.runWithCancellationToken(cancellationToken, (typeChecker2) => typeToDisplayParts(
152260
+ typeChecker2,
152261
+ type,
152262
+ getContainerNode(nodeForQuickInfo),
152263
+ /*flags*/
152264
+ void 0,
152265
+ verbosityLevel
152266
+ )),
151812
152267
  documentation: type.symbol ? type.symbol.getDocumentationComment(typeChecker) : void 0,
151813
152268
  tags: type.symbol ? type.symbol.getJsDocTags(typeChecker) : void 0
151814
152269
  };
151815
152270
  }
151816
- const { symbolKind, displayParts, documentation, tags } = typeChecker.runWithCancellationToken(cancellationToken, (typeChecker2) => ts_SymbolDisplay_exports.getSymbolDisplayPartsDocumentationAndSymbolKind(typeChecker2, symbol, sourceFile, getContainerNode(nodeForQuickInfo), nodeForQuickInfo));
152271
+ const { symbolKind, displayParts, documentation, tags, canIncreaseVerbosityLevel } = typeChecker.runWithCancellationToken(
152272
+ cancellationToken,
152273
+ (typeChecker2) => ts_SymbolDisplay_exports.getSymbolDisplayPartsDocumentationAndSymbolKind(
152274
+ typeChecker2,
152275
+ symbol,
152276
+ sourceFile,
152277
+ getContainerNode(nodeForQuickInfo),
152278
+ nodeForQuickInfo,
152279
+ /*semanticMeaning*/
152280
+ void 0,
152281
+ /*alias*/
152282
+ void 0,
152283
+ verbosityLevel
152284
+ )
152285
+ );
151817
152286
  return {
151818
152287
  kind: symbolKind,
151819
152288
  kindModifiers: ts_SymbolDisplay_exports.getSymbolModifiers(typeChecker, symbol),
151820
152289
  textSpan: createTextSpanFromNode(nodeForQuickInfo, sourceFile),
151821
152290
  displayParts,
151822
152291
  documentation,
151823
- tags
152292
+ tags,
152293
+ canIncreaseVerbosityLevel
151824
152294
  };
151825
152295
  }
151826
152296
  function preparePasteEditsForFile(fileName, copiedTextRange) {
@@ -152562,18 +153032,6 @@ function createLanguageService(host, documentRegistry = createDocumentRegistry(h
152562
153032
  preferences
152563
153033
  );
152564
153034
  }
152565
- function getImports(fileName) {
152566
- var _a2, _b;
152567
- synchronizeHostData();
152568
- const file = getValidSourceFile(fileName);
152569
- let imports;
152570
- for (const specifier of file.imports) {
152571
- if (nodeIsSynthesized(specifier)) continue;
152572
- const name = (_b = (_a2 = program.getResolvedModuleFromModuleSpecifier(specifier, file)) == null ? void 0 : _a2.resolvedModule) == null ? void 0 : _b.resolvedFileName;
152573
- if (name) (imports ?? (imports = /* @__PURE__ */ new Set())).add(name);
152574
- }
152575
- return imports ? arrayFrom(imports) : emptyArray;
152576
- }
152577
153035
  const ls = {
152578
153036
  dispose,
152579
153037
  cleanupSemanticCache,
@@ -152647,8 +153105,7 @@ function createLanguageService(host, documentRegistry = createDocumentRegistry(h
152647
153105
  getSupportedCodeFixes,
152648
153106
  preparePasteEditsForFile,
152649
153107
  getPasteEdits,
152650
- mapCode: mapCode2,
152651
- getImports
153108
+ mapCode: mapCode2
152652
153109
  };
152653
153110
  switch (languageServiceMode) {
152654
153111
  case 0 /* Semantic */:
@@ -156926,7 +157383,7 @@ function createImportAdderWorker(sourceFile, program, useAutoImportProvider, pre
156926
157383
  const removeExisting = /* @__PURE__ */ new Set();
156927
157384
  const verbatimImports = /* @__PURE__ */ new Set();
156928
157385
  const newImports = /* @__PURE__ */ new Map();
156929
- return { addImportFromDiagnostic, addImportFromExportedSymbol, writeFixes, hasFixes, addImportForUnresolvedIdentifier, addImportForNonExistentExport, removeExistingImport, addVerbatimImport };
157386
+ return { addImportFromDiagnostic, addImportFromExportedSymbol, addImportForModuleSymbol, writeFixes, hasFixes, addImportForUnresolvedIdentifier, addImportForNonExistentExport, removeExistingImport, addVerbatimImport };
156930
157387
  function addVerbatimImport(declaration) {
156931
157388
  verbatimImports.add(declaration);
156932
157389
  }
@@ -156942,7 +157399,7 @@ function createImportAdderWorker(sourceFile, program, useAutoImportProvider, pre
156942
157399
  }
156943
157400
  function addImportFromExportedSymbol(exportedSymbol, isValidTypeOnlyUseSite, referenceImport) {
156944
157401
  var _a, _b;
156945
- const moduleSymbol = Debug.checkDefined(exportedSymbol.parent);
157402
+ const moduleSymbol = Debug.checkDefined(exportedSymbol.parent, "Expected exported symbol to have module symbol as parent");
156946
157403
  const symbolName2 = getNameForExportedSymbol(exportedSymbol, getEmitScriptTarget(compilerOptions));
156947
157404
  const checker = program.getTypeChecker();
156948
157405
  const symbol = checker.getMergedSymbol(skipAlias(exportedSymbol, checker));
@@ -156992,6 +157449,75 @@ function createImportAdderWorker(sourceFile, program, useAutoImportProvider, pre
156992
157449
  addImport({ fix, symbolName: localName ?? symbolName2, errorIdentifierText: void 0 });
156993
157450
  }
156994
157451
  }
157452
+ function addImportForModuleSymbol(symbolAlias, isValidTypeOnlyUseSite, referenceImport) {
157453
+ var _a, _b, _c;
157454
+ const checker = program.getTypeChecker();
157455
+ const moduleSymbol = checker.getAliasedSymbol(symbolAlias);
157456
+ Debug.assert(moduleSymbol.flags & 1536 /* Module */, "Expected symbol to be a module");
157457
+ const moduleSpecifierResolutionHost = createModuleSpecifierResolutionHost(program, host);
157458
+ const moduleSpecifierResult = ts_moduleSpecifiers_exports.getModuleSpecifiersWithCacheInfo(
157459
+ moduleSymbol,
157460
+ checker,
157461
+ compilerOptions,
157462
+ sourceFile,
157463
+ moduleSpecifierResolutionHost,
157464
+ preferences,
157465
+ /*options*/
157466
+ void 0,
157467
+ /*forAutoImport*/
157468
+ true
157469
+ );
157470
+ const useRequire = shouldUseRequire(sourceFile, program);
157471
+ let addAsTypeOnly = getAddAsTypeOnly(
157472
+ isValidTypeOnlyUseSite,
157473
+ /*isForNewImportDeclaration*/
157474
+ true,
157475
+ /*symbol*/
157476
+ void 0,
157477
+ symbolAlias.flags,
157478
+ program.getTypeChecker(),
157479
+ compilerOptions
157480
+ );
157481
+ addAsTypeOnly = addAsTypeOnly === 1 /* Allowed */ && isTypeOnlyImportDeclaration(referenceImport) ? 2 /* Required */ : 1 /* Allowed */;
157482
+ const importKind = isImportDeclaration(referenceImport) ? isDefaultImport(referenceImport) ? 1 /* Default */ : 2 /* Namespace */ : isImportSpecifier(referenceImport) ? 0 /* Named */ : isImportClause(referenceImport) && !!referenceImport.name ? 1 /* Default */ : 2 /* Namespace */;
157483
+ const exportInfo = [{
157484
+ symbol: symbolAlias,
157485
+ moduleSymbol,
157486
+ moduleFileName: (_c = (_b = (_a = moduleSymbol.declarations) == null ? void 0 : _a[0]) == null ? void 0 : _b.getSourceFile()) == null ? void 0 : _c.fileName,
157487
+ exportKind: 4 /* Module */,
157488
+ targetFlags: symbolAlias.flags,
157489
+ isFromPackageJson: false
157490
+ }];
157491
+ const existingFix = getImportFixForSymbol(
157492
+ sourceFile,
157493
+ exportInfo,
157494
+ program,
157495
+ /*position*/
157496
+ void 0,
157497
+ !!isValidTypeOnlyUseSite,
157498
+ useRequire,
157499
+ host,
157500
+ preferences
157501
+ );
157502
+ let fix;
157503
+ if (existingFix && importKind !== 2 /* Namespace */) {
157504
+ fix = {
157505
+ ...existingFix,
157506
+ addAsTypeOnly,
157507
+ importKind
157508
+ };
157509
+ } else {
157510
+ fix = {
157511
+ kind: 3 /* AddNew */,
157512
+ moduleSpecifierKind: existingFix !== void 0 ? existingFix.moduleSpecifierKind : moduleSpecifierResult.kind,
157513
+ moduleSpecifier: existingFix !== void 0 ? existingFix.moduleSpecifier : first(moduleSpecifierResult.moduleSpecifiers),
157514
+ importKind,
157515
+ addAsTypeOnly,
157516
+ useRequire
157517
+ };
157518
+ }
157519
+ addImport({ fix, symbolName: symbolAlias.name, errorIdentifierText: void 0 });
157520
+ }
156995
157521
  function addImportForNonExistentExport(exportName, exportingFileName, exportKind, exportedMeanings, isImportUsageValidAsTypeOnly) {
156996
157522
  const exportingSourceFile = program.getSourceFile(exportingFileName);
156997
157523
  const useRequire = shouldUseRequire(sourceFile, program);
@@ -157440,7 +157966,8 @@ function getAllExportInfoForSymbol(importingFile, symbol, symbolName2, moduleSym
157440
157966
  const moduleSourceFile = isFileExcluded && mergedModuleSymbol.declarations && getDeclarationOfKind(mergedModuleSymbol, 307 /* SourceFile */);
157441
157967
  const moduleSymbolExcluded = moduleSourceFile && isFileExcluded(moduleSourceFile);
157442
157968
  return getExportInfoMap(importingFile, host, program, preferences, cancellationToken).search(importingFile.path, preferCapitalized, (name) => name === symbolName2, (info) => {
157443
- if (getChecker(info[0].isFromPackageJson).getMergedSymbol(skipAlias(info[0].symbol, getChecker(info[0].isFromPackageJson))) === symbol && (moduleSymbolExcluded || info.some((i) => i.moduleSymbol === moduleSymbol || i.symbol.parent === moduleSymbol))) {
157969
+ const checker = getChecker(info[0].isFromPackageJson);
157970
+ if (checker.getMergedSymbol(skipAlias(info[0].symbol, checker)) === symbol && (moduleSymbolExcluded || info.some((i) => checker.getMergedSymbol(i.moduleSymbol) === moduleSymbol || i.symbol.parent === moduleSymbol))) {
157444
157971
  return info;
157445
157972
  }
157446
157973
  });
@@ -157869,6 +158396,8 @@ function getImportKind(importingFile, exportKind, program, forceImportKeyword) {
157869
158396
  return getExportEqualsImportKind(importingFile, program.getCompilerOptions(), !!forceImportKeyword);
157870
158397
  case 3 /* UMD */:
157871
158398
  return getUmdImportKind(importingFile, program, !!forceImportKeyword);
158399
+ case 4 /* Module */:
158400
+ return 2 /* Namespace */;
157872
158401
  default:
157873
158402
  return Debug.assertNever(exportKind);
157874
158403
  }
@@ -159306,7 +159835,8 @@ var errorCodes28 = [
159306
159835
  Diagnostics.Type_0_is_missing_the_following_properties_from_type_1_Colon_2.code,
159307
159836
  Diagnostics.Type_0_is_missing_the_following_properties_from_type_1_Colon_2_and_3_more.code,
159308
159837
  Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1.code,
159309
- Diagnostics.Cannot_find_name_0.code
159838
+ Diagnostics.Cannot_find_name_0.code,
159839
+ Diagnostics.Type_0_does_not_satisfy_the_expected_type_1.code
159310
159840
  ];
159311
159841
  registerCodeFix({
159312
159842
  errorCodes: errorCodes28,
@@ -159343,9 +159873,9 @@ registerCodeFix({
159343
159873
  return createCombinedCodeActions(ts_textChanges_exports.ChangeTracker.with(context, (changes) => {
159344
159874
  eachDiagnostic(context, errorCodes28, (diag2) => {
159345
159875
  const info = getInfo10(diag2.file, diag2.start, diag2.code, checker, context.program);
159346
- if (!info || !addToSeen(seen, getNodeId(info.parentDeclaration) + "#" + (info.kind === 3 /* ObjectLiteral */ ? info.identifier : info.token.text))) {
159347
- return;
159348
- }
159876
+ if (info === void 0) return;
159877
+ const nodeId = getNodeId(info.parentDeclaration) + "#" + (info.kind === 3 /* ObjectLiteral */ ? info.identifier || getNodeId(info.token) : info.token.text);
159878
+ if (!addToSeen(seen, nodeId)) return;
159349
159879
  if (fixId56 === fixMissingFunctionDeclaration && (info.kind === 2 /* Function */ || info.kind === 5 /* Signature */)) {
159350
159880
  addFunctionDeclaration(changes, context, info);
159351
159881
  } else if (fixId56 === fixMissingProperties && info.kind === 3 /* ObjectLiteral */) {
@@ -159389,7 +159919,7 @@ registerCodeFix({
159389
159919
  }
159390
159920
  });
159391
159921
  function getInfo10(sourceFile, tokenPos, errorCode, checker, program) {
159392
- var _a, _b, _c;
159922
+ var _a, _b;
159393
159923
  const token = getTokenAtPosition(sourceFile, tokenPos);
159394
159924
  const parent2 = token.parent;
159395
159925
  if (errorCode === Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1.code) {
@@ -159411,23 +159941,25 @@ function getInfo10(sourceFile, tokenPos, errorCode, checker, program) {
159411
159941
  if (!length(properties)) return void 0;
159412
159942
  return { kind: 3 /* ObjectLiteral */, token: param.name, identifier: param.name.text, properties, parentDeclaration: parent2 };
159413
159943
  }
159414
- if (token.kind === 19 /* OpenBraceToken */ && isObjectLiteralExpression(parent2)) {
159415
- const targetType = (_a = checker.getContextualType(parent2) || checker.getTypeAtLocation(parent2)) == null ? void 0 : _a.getNonNullableType();
159416
- const properties = arrayFrom(checker.getUnmatchedProperties(
159417
- checker.getTypeAtLocation(parent2),
159418
- targetType,
159419
- /*requireOptionalProperties*/
159420
- false,
159421
- /*matchDiscriminantProperties*/
159422
- false
159423
- ));
159424
- if (!length(properties)) return void 0;
159425
- const identifier = "";
159426
- return { kind: 3 /* ObjectLiteral */, token: parent2, identifier, properties, parentDeclaration: parent2 };
159944
+ if (token.kind === 19 /* OpenBraceToken */ || isSatisfiesExpression(parent2) || isReturnStatement(parent2)) {
159945
+ const expression = (isSatisfiesExpression(parent2) || isReturnStatement(parent2)) && parent2.expression ? parent2.expression : parent2;
159946
+ if (isObjectLiteralExpression(expression)) {
159947
+ const targetType = isSatisfiesExpression(parent2) ? checker.getTypeFromTypeNode(parent2.type) : checker.getContextualType(expression) || checker.getTypeAtLocation(expression);
159948
+ const properties = arrayFrom(checker.getUnmatchedProperties(
159949
+ checker.getTypeAtLocation(parent2),
159950
+ targetType.getNonNullableType(),
159951
+ /*requireOptionalProperties*/
159952
+ false,
159953
+ /*matchDiscriminantProperties*/
159954
+ false
159955
+ ));
159956
+ if (!length(properties)) return void 0;
159957
+ return { kind: 3 /* ObjectLiteral */, token: parent2, identifier: void 0, properties, parentDeclaration: expression, indentation: isReturnStatement(expression.parent) || isYieldExpression(expression.parent) ? 0 : void 0 };
159958
+ }
159427
159959
  }
159428
159960
  if (!isMemberName(token)) return void 0;
159429
159961
  if (isIdentifier(token) && hasInitializer(parent2) && parent2.initializer && isObjectLiteralExpression(parent2.initializer)) {
159430
- const targetType = (_b = checker.getContextualType(token) || checker.getTypeAtLocation(token)) == null ? void 0 : _b.getNonNullableType();
159962
+ const targetType = (_a = checker.getContextualType(token) || checker.getTypeAtLocation(token)) == null ? void 0 : _a.getNonNullableType();
159431
159963
  const properties = arrayFrom(checker.getUnmatchedProperties(
159432
159964
  checker.getTypeAtLocation(parent2.initializer),
159433
159965
  targetType,
@@ -159446,7 +159978,7 @@ function getInfo10(sourceFile, tokenPos, errorCode, checker, program) {
159446
159978
  return { kind: 4 /* JsxAttributes */, token, attributes, parentDeclaration: token.parent };
159447
159979
  }
159448
159980
  if (isIdentifier(token)) {
159449
- const type = (_c = checker.getContextualType(token)) == null ? void 0 : _c.getNonNullableType();
159981
+ const type = (_b = checker.getContextualType(token)) == null ? void 0 : _b.getNonNullableType();
159450
159982
  if (type && getObjectFlags(type) & 16 /* Anonymous */) {
159451
159983
  const signature = firstOrUndefined(checker.getSignaturesOfType(type, 0 /* Call */));
159452
159984
  if (signature === void 0) return void 0;
@@ -163887,12 +164419,10 @@ function typeToAutoImportableTypeNode(checker, importAdder, type, contextNode, s
163887
164419
  return typeNodeToAutoImportableTypeNode(typeNode, importAdder, scriptTarget);
163888
164420
  }
163889
164421
  function typeNodeToAutoImportableTypeNode(typeNode, importAdder, scriptTarget) {
163890
- if (typeNode && isImportTypeNode(typeNode)) {
163891
- const importableReference = tryGetAutoImportableReferenceFromTypeNode(typeNode, scriptTarget);
163892
- if (importableReference) {
163893
- importSymbols(importAdder, importableReference.symbols);
163894
- typeNode = importableReference.typeNode;
163895
- }
164422
+ const importableReference = tryGetAutoImportableReferenceFromTypeNode(typeNode, scriptTarget);
164423
+ if (importableReference) {
164424
+ importSymbols(importAdder, importableReference.symbols);
164425
+ typeNode = importableReference.typeNode;
163896
164426
  }
163897
164427
  return getSynthesizedDeepClone(typeNode);
163898
164428
  }
@@ -176824,7 +177354,7 @@ function getSymbolModifiers(typeChecker, symbol) {
176824
177354
  }
176825
177355
  return modifiers.size > 0 ? arrayFrom(modifiers.values()).join(",") : "" /* none */;
176826
177356
  }
176827
- function getSymbolDisplayPartsDocumentationAndSymbolKindWorker(typeChecker, symbol, sourceFile, enclosingDeclaration, location, type, semanticMeaning, alias) {
177357
+ function getSymbolDisplayPartsDocumentationAndSymbolKindWorker(typeChecker, symbol, sourceFile, enclosingDeclaration, location, type, semanticMeaning, alias, verbosityLevel) {
176828
177358
  var _a;
176829
177359
  const displayParts = [];
176830
177360
  let documentation = [];
@@ -176836,6 +177366,7 @@ function getSymbolDisplayPartsDocumentationAndSymbolKindWorker(typeChecker, symb
176836
177366
  let documentationFromAlias;
176837
177367
  let tagsFromAlias;
176838
177368
  let hasMultipleSignatures = false;
177369
+ const typeWriterOut = verbosityLevel !== void 0 ? { couldUnfoldMore: false } : void 0;
176839
177370
  if (location.kind === 110 /* ThisKeyword */ && !isThisExpression) {
176840
177371
  return { displayParts: [keywordPart(110 /* ThisKeyword */)], documentation: [], symbolKind: "primitive type" /* primitiveType */, tags: void 0 };
176841
177372
  }
@@ -176995,7 +177526,17 @@ function getSymbolDisplayPartsDocumentationAndSymbolKindWorker(typeChecker, symb
176995
177526
  displayParts.push(spacePart());
176996
177527
  displayParts.push(operatorPart(64 /* EqualsToken */));
176997
177528
  displayParts.push(spacePart());
176998
- addRange(displayParts, typeToDisplayParts(typeChecker, location.parent && isConstTypeReference(location.parent) ? typeChecker.getTypeAtLocation(location.parent) : typeChecker.getDeclaredTypeOfSymbol(symbol), enclosingDeclaration, 8388608 /* InTypeAlias */));
177529
+ addRange(
177530
+ displayParts,
177531
+ typeToDisplayParts(
177532
+ typeChecker,
177533
+ location.parent && isConstTypeReference(location.parent) ? typeChecker.getTypeAtLocation(location.parent) : typeChecker.getDeclaredTypeOfSymbol(symbol),
177534
+ enclosingDeclaration,
177535
+ 8388608 /* InTypeAlias */,
177536
+ verbosityLevel,
177537
+ typeWriterOut
177538
+ )
177539
+ );
176999
177540
  }
177000
177541
  if (symbolFlags & 384 /* Enum */) {
177001
177542
  prefixNextMeaning();
@@ -177154,12 +177695,32 @@ function getSymbolDisplayPartsDocumentationAndSymbolKindWorker(typeChecker, symb
177154
177695
  displayParts.push(spacePart());
177155
177696
  if (type.symbol && type.symbol.flags & 262144 /* TypeParameter */ && symbolKind !== "index" /* indexSignatureElement */) {
177156
177697
  const typeParameterParts = mapToDisplayParts((writer) => {
177157
- const param = typeChecker.typeParameterToDeclaration(type, enclosingDeclaration, symbolDisplayNodeBuilderFlags);
177698
+ const param = typeChecker.typeParameterToDeclaration(
177699
+ type,
177700
+ enclosingDeclaration,
177701
+ symbolDisplayNodeBuilderFlags,
177702
+ /*internalFlags*/
177703
+ void 0,
177704
+ /*tracker*/
177705
+ void 0,
177706
+ verbosityLevel
177707
+ );
177158
177708
  getPrinter().writeNode(4 /* Unspecified */, param, getSourceFileOfNode(getParseTreeNode(enclosingDeclaration)), writer);
177159
177709
  });
177160
177710
  addRange(displayParts, typeParameterParts);
177161
177711
  } else {
177162
- addRange(displayParts, typeToDisplayParts(typeChecker, type, enclosingDeclaration));
177712
+ addRange(
177713
+ displayParts,
177714
+ typeToDisplayParts(
177715
+ typeChecker,
177716
+ type,
177717
+ enclosingDeclaration,
177718
+ /*flags*/
177719
+ void 0,
177720
+ verbosityLevel,
177721
+ typeWriterOut
177722
+ )
177723
+ );
177163
177724
  }
177164
177725
  if (isTransientSymbol(symbol) && symbol.links.target && isTransientSymbol(symbol.links.target) && symbol.links.target.links.tupleLabelDeclaration) {
177165
177726
  const labelDecl = symbol.links.target.links.tupleLabelDeclaration;
@@ -177224,7 +177785,13 @@ function getSymbolDisplayPartsDocumentationAndSymbolKindWorker(typeChecker, symb
177224
177785
  if (tags.length === 0 && tagsFromAlias) {
177225
177786
  tags = tagsFromAlias;
177226
177787
  }
177227
- return { displayParts, documentation, symbolKind, tags: tags.length === 0 ? void 0 : tags };
177788
+ return {
177789
+ displayParts,
177790
+ documentation,
177791
+ symbolKind,
177792
+ tags: tags.length === 0 ? void 0 : tags,
177793
+ canIncreaseVerbosityLevel: typeWriterOut == null ? void 0 : typeWriterOut.couldUnfoldMore
177794
+ };
177228
177795
  function getPrinter() {
177229
177796
  return createPrinterWithRemoveComments();
177230
177797
  }
@@ -177337,7 +177904,7 @@ function getSymbolDisplayPartsDocumentationAndSymbolKindWorker(typeChecker, symb
177337
177904
  addRange(displayParts, typeParameterParts);
177338
177905
  }
177339
177906
  }
177340
- function getSymbolDisplayPartsDocumentationAndSymbolKind(typeChecker, symbol, sourceFile, enclosingDeclaration, location, semanticMeaning = getMeaningFromLocation(location), alias) {
177907
+ function getSymbolDisplayPartsDocumentationAndSymbolKind(typeChecker, symbol, sourceFile, enclosingDeclaration, location, semanticMeaning = getMeaningFromLocation(location), alias, verbosityLevel) {
177341
177908
  return getSymbolDisplayPartsDocumentationAndSymbolKindWorker(
177342
177909
  typeChecker,
177343
177910
  symbol,
@@ -177347,7 +177914,8 @@ function getSymbolDisplayPartsDocumentationAndSymbolKind(typeChecker, symbol, so
177347
177914
  /*type*/
177348
177915
  void 0,
177349
177916
  semanticMeaning,
177350
- alias
177917
+ alias,
177918
+ verbosityLevel
177351
177919
  );
177352
177920
  }
177353
177921
  function isLocalVariableOrFunction(symbol) {
@@ -193033,8 +193601,8 @@ var Session3 = class _Session {
193033
193601
  ["mapCode" /* MapCode */]: (request) => {
193034
193602
  return this.requiredResponse(this.mapCode(request.arguments));
193035
193603
  },
193036
- ["copilotRelated" /* CopilotRelated */]: (request) => {
193037
- return this.requiredResponse(this.getCopilotRelatedInfo(request.arguments));
193604
+ ["copilotRelated" /* CopilotRelated */]: () => {
193605
+ return this.requiredResponse(this.getCopilotRelatedInfo());
193038
193606
  }
193039
193607
  }));
193040
193608
  this.host = opts.host;
@@ -193982,10 +194550,9 @@ Project '${project.projectName}' (${ProjectKind[project.projectKind]}) ${counter
193982
194550
  const changes = languageService.mapCode(file, args.mapping.contents, focusLocations, formatOptions, preferences);
193983
194551
  return this.mapTextChangesToCodeEdits(changes);
193984
194552
  }
193985
- getCopilotRelatedInfo(args) {
193986
- const { file, project } = this.getFileAndProject(args);
194553
+ getCopilotRelatedInfo() {
193987
194554
  return {
193988
- relatedFiles: project.getLanguageService().getImports(file)
194555
+ relatedFiles: []
193989
194556
  };
193990
194557
  }
193991
194558
  setCompilerOptionsForInferredProjects(args) {
@@ -194290,7 +194857,7 @@ Project '${project.projectName}' (${ProjectKind[project.projectKind]}) ${counter
194290
194857
  getQuickInfoWorker(args, simplifiedResult) {
194291
194858
  const { file, project } = this.getFileAndProject(args);
194292
194859
  const scriptInfo = this.projectService.getScriptInfoForNormalizedPath(file);
194293
- const quickInfo = project.getLanguageService().getQuickInfoAtPosition(file, this.getPosition(args, scriptInfo));
194860
+ const quickInfo = project.getLanguageService().getQuickInfoAtPosition(file, this.getPosition(args, scriptInfo), args.verbosityLevel);
194294
194861
  if (!quickInfo) {
194295
194862
  return void 0;
194296
194863
  }
@@ -194304,7 +194871,8 @@ Project '${project.projectName}' (${ProjectKind[project.projectKind]}) ${counter
194304
194871
  end: scriptInfo.positionToLineOffset(textSpanEnd(quickInfo.textSpan)),
194305
194872
  displayString,
194306
194873
  documentation: useDisplayParts ? this.mapDisplayParts(quickInfo.documentation, project) : displayPartsToString(quickInfo.documentation),
194307
- tags: this.mapJSDocTagInfo(quickInfo.tags, project, useDisplayParts)
194874
+ tags: this.mapJSDocTagInfo(quickInfo.tags, project, useDisplayParts),
194875
+ canIncreaseVerbosityLevel: quickInfo.canIncreaseVerbosityLevel
194308
194876
  };
194309
194877
  } else {
194310
194878
  return useDisplayParts ? quickInfo : {
@@ -194785,6 +195353,7 @@ Project '${project.projectName}' (${ProjectKind[project.projectKind]}) ${counter
194785
195353
  }
194786
195354
  getPasteEdits(args) {
194787
195355
  const { file, project } = this.getFileAndProject(args);
195356
+ if (isDynamicFileName(file)) return void 0;
194788
195357
  const copiedFrom = args.copiedFrom ? { file: args.copiedFrom.file, range: args.copiedFrom.spans.map((copies) => this.getRange({ file: args.copiedFrom.file, startLine: copies.start.line, startOffset: copies.start.offset, endLine: copies.end.line, endOffset: copies.end.offset }, project.getScriptInfoForNormalizedPath(toNormalizedPath(args.copiedFrom.file)))) } : void 0;
194789
195358
  const result = project.getLanguageService().getPasteEdits(
194790
195359
  {