typescript 4.8.0-dev.20220706 → 4.8.0-dev.20220709

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.
@@ -89,7 +89,7 @@ var ts;
89
89
  // The following is baselined as a literal template type without intervention
90
90
  /** The version of the TypeScript compiler release */
91
91
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
92
- ts.version = ts.versionMajorMinor + ".0-dev.20220706";
92
+ ts.version = ts.versionMajorMinor + ".0-dev.20220709";
93
93
  /* @internal */
94
94
  var Comparison;
95
95
  (function (Comparison) {
@@ -2045,7 +2045,7 @@ var ts;
2045
2045
  * and 1 insertion/deletion at 3 characters)
2046
2046
  */
2047
2047
  function getSpellingSuggestion(name, candidates, getName) {
2048
- var maximumLengthDifference = Math.min(2, Math.floor(name.length * 0.34));
2048
+ var maximumLengthDifference = Math.max(2, Math.floor(name.length * 0.34));
2049
2049
  var bestDistance = Math.floor(name.length * 0.4) + 1; // If the best result is worse than this, don't bother.
2050
2050
  var bestCandidate;
2051
2051
  for (var _i = 0, candidates_2 = candidates; _i < candidates_2.length; _i++) {
@@ -2774,6 +2774,22 @@ var ts;
2774
2774
  return formatEnum(flags, ts.FlowFlags, /*isFlags*/ true);
2775
2775
  }
2776
2776
  Debug.formatFlowFlags = formatFlowFlags;
2777
+ function formatRelationComparisonResult(result) {
2778
+ return formatEnum(result, ts.RelationComparisonResult, /*isFlags*/ true);
2779
+ }
2780
+ Debug.formatRelationComparisonResult = formatRelationComparisonResult;
2781
+ function formatCheckMode(mode) {
2782
+ return formatEnum(mode, ts.CheckMode, /*isFlags*/ true);
2783
+ }
2784
+ Debug.formatCheckMode = formatCheckMode;
2785
+ function formatSignatureCheckMode(mode) {
2786
+ return formatEnum(mode, ts.SignatureCheckMode, /*isFlags*/ true);
2787
+ }
2788
+ Debug.formatSignatureCheckMode = formatSignatureCheckMode;
2789
+ function formatTypeFacts(facts) {
2790
+ return formatEnum(facts, ts.TypeFacts, /*isFlags*/ true);
2791
+ }
2792
+ Debug.formatTypeFacts = formatTypeFacts;
2777
2793
  var isDebugInfoEnabled = false;
2778
2794
  var extendedDebugModule;
2779
2795
  function extendedDebug() {
@@ -9013,6 +9029,7 @@ var ts;
9013
9029
  The_type_of_this_expression_cannot_be_named_without_a_resolution_mode_assertion_which_is_an_unstable_feature_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next: diag(2841, ts.DiagnosticCategory.Error, "The_type_of_this_expression_cannot_be_named_without_a_resolution_mode_assertion_which_is_an_unstable_2841", "The type of this expression cannot be named without a 'resolution-mode' assertion, which is an unstable feature. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'."),
9014
9030
  _0_is_an_unused_renaming_of_1_Did_you_intend_to_use_it_as_a_type_annotation: diag(2842, ts.DiagnosticCategory.Error, "_0_is_an_unused_renaming_of_1_Did_you_intend_to_use_it_as_a_type_annotation_2842", "'{0}' is an unused renaming of '{1}'. Did you intend to use it as a type annotation?"),
9015
9031
  We_can_only_write_a_type_for_0_by_adding_a_type_for_the_entire_parameter_here: diag(2843, ts.DiagnosticCategory.Error, "We_can_only_write_a_type_for_0_by_adding_a_type_for_the_entire_parameter_here_2843", "We can only write a type for '{0}' by adding a type for the entire parameter here."),
9032
+ Type_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: diag(2844, ts.DiagnosticCategory.Error, "Type_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor_2844", "Type of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor."),
9016
9033
  Import_declaration_0_is_using_private_name_1: diag(4000, ts.DiagnosticCategory.Error, "Import_declaration_0_is_using_private_name_1_4000", "Import declaration '{0}' is using private name '{1}'."),
9017
9034
  Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: diag(4002, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_class_has_or_is_using_private_name_1_4002", "Type parameter '{0}' of exported class has or is using private name '{1}'."),
9018
9035
  Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: diag(4004, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1_4004", "Type parameter '{0}' of exported interface has or is using private name '{1}'."),
@@ -19511,7 +19528,8 @@ var ts;
19511
19528
  function getDeclarationModifierFlagsFromSymbol(s, isWrite) {
19512
19529
  if (isWrite === void 0) { isWrite = false; }
19513
19530
  if (s.valueDeclaration) {
19514
- var declaration = (isWrite && s.declarations && ts.find(s.declarations, function (d) { return d.kind === 173 /* SetAccessor */; })) || s.valueDeclaration;
19531
+ var declaration = (isWrite && s.declarations && ts.find(s.declarations, ts.isSetAccessorDeclaration))
19532
+ || (s.flags & 32768 /* GetAccessor */ && ts.find(s.declarations, ts.isGetAccessorDeclaration)) || s.valueDeclaration;
19515
19533
  var flags = ts.getCombinedModifierFlags(declaration);
19516
19534
  return s.parent && s.parent.flags & 32 /* Class */ ? flags : flags & ~28 /* AccessibilityModifier */;
19517
19535
  }
@@ -20186,7 +20204,7 @@ var ts;
20186
20204
  // Excludes declaration files - they still require an explicit `export {}` or the like
20187
20205
  // for back compat purposes. The only non-declaration files _not_ forced to be a module are `.js` files
20188
20206
  // that aren't esm-mode (meaning not in a `type: module` scope).
20189
- return (file.impliedNodeFormat === ts.ModuleKind.ESNext || (ts.fileExtensionIsOneOf(file.fileName, [".cjs" /* Cjs */, ".cts" /* Cts */]))) && !file.isDeclarationFile ? true : undefined;
20207
+ return (file.impliedNodeFormat === ts.ModuleKind.ESNext || (ts.fileExtensionIsOneOf(file.fileName, [".cjs" /* Cjs */, ".cts" /* Cts */, ".mjs" /* Mjs */, ".mts" /* Mts */]))) && !file.isDeclarationFile ? true : undefined;
20190
20208
  }
20191
20209
  function getSetExternalModuleIndicator(options) {
20192
20210
  // TODO: Should this callback be cached?
@@ -20209,10 +20227,7 @@ var ts;
20209
20227
  if (options.jsx === 4 /* ReactJSX */ || options.jsx === 5 /* ReactJSXDev */) {
20210
20228
  checks.push(isFileModuleFromUsingJSXTag);
20211
20229
  }
20212
- var moduleKind = getEmitModuleKind(options);
20213
- if (moduleKind === ts.ModuleKind.Node16 || moduleKind === ts.ModuleKind.NodeNext) {
20214
- checks.push(isFileForcedToBeModuleByFormat);
20215
- }
20230
+ checks.push(isFileForcedToBeModuleByFormat);
20216
20231
  var combined_1 = ts.or.apply(void 0, checks);
20217
20232
  var callback = function (file) { return void (file.externalModuleIndicator = combined_1(file)); };
20218
20233
  return callback;
@@ -33932,10 +33947,10 @@ var ts;
33932
33947
  var hasJSDoc = hasPrecedingJSDocComment();
33933
33948
  var modifiers = parseModifiers();
33934
33949
  if (parseContextualModifier(136 /* GetKeyword */)) {
33935
- return parseAccessorDeclaration(pos, hasJSDoc, /*decorators*/ undefined, modifiers, 172 /* GetAccessor */);
33950
+ return parseAccessorDeclaration(pos, hasJSDoc, /*decorators*/ undefined, modifiers, 172 /* GetAccessor */, 4 /* Type */);
33936
33951
  }
33937
33952
  if (parseContextualModifier(149 /* SetKeyword */)) {
33938
- return parseAccessorDeclaration(pos, hasJSDoc, /*decorators*/ undefined, modifiers, 173 /* SetAccessor */);
33953
+ return parseAccessorDeclaration(pos, hasJSDoc, /*decorators*/ undefined, modifiers, 173 /* SetAccessor */, 4 /* Type */);
33939
33954
  }
33940
33955
  if (isIndexSignature()) {
33941
33956
  return parseIndexSignatureDeclaration(pos, hasJSDoc, /*decorators*/ undefined, modifiers);
@@ -35981,10 +35996,10 @@ var ts;
35981
35996
  var decorators = parseDecorators();
35982
35997
  var modifiers = parseModifiers();
35983
35998
  if (parseContextualModifier(136 /* GetKeyword */)) {
35984
- return parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, 172 /* GetAccessor */);
35999
+ return parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, 172 /* GetAccessor */, 0 /* None */);
35985
36000
  }
35986
36001
  if (parseContextualModifier(149 /* SetKeyword */)) {
35987
- return parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, 173 /* SetAccessor */);
36002
+ return parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, 173 /* SetAccessor */, 0 /* None */);
35988
36003
  }
35989
36004
  var asteriskToken = parseOptionalToken(41 /* AsteriskToken */);
35990
36005
  var tokenIsIdentifier = isIdentifier();
@@ -36676,9 +36691,15 @@ var ts;
36676
36691
  return !scanner.hasPrecedingLineBreak() && (isIdentifier() || token() === 10 /* StringLiteral */);
36677
36692
  }
36678
36693
  function parseFunctionBlockOrSemicolon(flags, diagnosticMessage) {
36679
- if (token() !== 18 /* OpenBraceToken */ && canParseSemicolon()) {
36680
- parseSemicolon();
36681
- return;
36694
+ if (token() !== 18 /* OpenBraceToken */) {
36695
+ if (flags & 4 /* Type */) {
36696
+ parseTypeMemberSemicolon();
36697
+ return;
36698
+ }
36699
+ if (canParseSemicolon()) {
36700
+ parseSemicolon();
36701
+ return;
36702
+ }
36682
36703
  }
36683
36704
  return parseFunctionBlock(flags, diagnosticMessage);
36684
36705
  }
@@ -36882,12 +36903,12 @@ var ts;
36882
36903
  }
36883
36904
  return parsePropertyDeclaration(pos, hasJSDoc, decorators, modifiers, name, questionToken);
36884
36905
  }
36885
- function parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, kind) {
36906
+ function parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, kind, flags) {
36886
36907
  var name = parsePropertyName();
36887
36908
  var typeParameters = parseTypeParameters();
36888
36909
  var parameters = parseParameters(0 /* None */);
36889
36910
  var type = parseReturnType(58 /* ColonToken */, /*isType*/ false);
36890
- var body = parseFunctionBlockOrSemicolon(0 /* None */);
36911
+ var body = parseFunctionBlockOrSemicolon(flags);
36891
36912
  var node = kind === 172 /* GetAccessor */
36892
36913
  ? factory.createGetAccessorDeclaration(combineDecoratorsAndModifiers(decorators, modifiers), name, parameters, type, body)
36893
36914
  : factory.createSetAccessorDeclaration(combineDecoratorsAndModifiers(decorators, modifiers), name, parameters, body);
@@ -37074,10 +37095,10 @@ var ts;
37074
37095
  return parseClassStaticBlockDeclaration(pos, hasJSDoc, decorators, modifiers);
37075
37096
  }
37076
37097
  if (parseContextualModifier(136 /* GetKeyword */)) {
37077
- return parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, 172 /* GetAccessor */);
37098
+ return parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, 172 /* GetAccessor */, 0 /* None */);
37078
37099
  }
37079
37100
  if (parseContextualModifier(149 /* SetKeyword */)) {
37080
- return parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, 173 /* SetAccessor */);
37101
+ return parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, 173 /* SetAccessor */, 0 /* None */);
37081
37102
  }
37082
37103
  if (token() === 134 /* ConstructorKeyword */ || token() === 10 /* StringLiteral */) {
37083
37104
  var constructorDeclaration = tryParseConstructorDeclaration(pos, hasJSDoc, decorators, modifiers);
@@ -44388,6 +44409,7 @@ var ts;
44388
44409
  return toSearchResult(/*value*/ undefined);
44389
44410
  }
44390
44411
  /**
44412
+ * @internal
44391
44413
  * From https://github.com/nodejs/node/blob/8f39f51cbbd3b2de14b9ee896e26421cc5b20121/lib/internal/modules/esm/resolve.js#L722 -
44392
44414
  * "longest" has some nuance as to what "longest" means in the presence of pattern trailers
44393
44415
  */
@@ -44410,6 +44432,7 @@ var ts;
44410
44432
  return 1;
44411
44433
  return 0;
44412
44434
  }
44435
+ ts.comparePatternKeys = comparePatternKeys;
44413
44436
  function loadModuleFromImportsOrExports(extensions, state, cache, redirectedReference, moduleName, lookupTable, scope, isImports) {
44414
44437
  var loadModuleFromTargetImportOrExport = getLoadModuleFromTargetImportOrExport(extensions, state, cache, redirectedReference, moduleName, scope, isImports);
44415
44438
  if (!ts.endsWith(moduleName, ts.directorySeparator) && moduleName.indexOf("*") === -1 && ts.hasProperty(lookupTable, moduleName)) {
@@ -48481,7 +48504,7 @@ var ts;
48481
48504
  // Masks
48482
48505
  TypeFacts[TypeFacts["OrFactsMask"] = 8256] = "OrFactsMask";
48483
48506
  TypeFacts[TypeFacts["AndFactsMask"] = 134209471] = "AndFactsMask";
48484
- })(TypeFacts || (TypeFacts = {}));
48507
+ })(TypeFacts = ts.TypeFacts || (ts.TypeFacts = {}));
48485
48508
  var typeofNEFacts = new ts.Map(ts.getEntries({
48486
48509
  string: 256 /* TypeofNEString */,
48487
48510
  number: 512 /* TypeofNENumber */,
@@ -48516,7 +48539,7 @@ var ts;
48516
48539
  CheckMode[CheckMode["RestBindingElement"] = 64] = "RestBindingElement";
48517
48540
  // e.g. in `const { a, ...rest } = foo`, when checking the type of `foo` to determine the type of `rest`,
48518
48541
  // we need to preserve generic types instead of substituting them for constraints
48519
- })(CheckMode || (CheckMode = {}));
48542
+ })(CheckMode = ts.CheckMode || (ts.CheckMode = {}));
48520
48543
  var SignatureCheckMode;
48521
48544
  (function (SignatureCheckMode) {
48522
48545
  SignatureCheckMode[SignatureCheckMode["BivariantCallback"] = 1] = "BivariantCallback";
@@ -48524,7 +48547,7 @@ var ts;
48524
48547
  SignatureCheckMode[SignatureCheckMode["IgnoreReturnTypes"] = 4] = "IgnoreReturnTypes";
48525
48548
  SignatureCheckMode[SignatureCheckMode["StrictArity"] = 8] = "StrictArity";
48526
48549
  SignatureCheckMode[SignatureCheckMode["Callback"] = 3] = "Callback";
48527
- })(SignatureCheckMode || (SignatureCheckMode = {}));
48550
+ })(SignatureCheckMode = ts.SignatureCheckMode || (ts.SignatureCheckMode = {}));
48528
48551
  var IntersectionState;
48529
48552
  (function (IntersectionState) {
48530
48553
  IntersectionState[IntersectionState["None"] = 0] = "None";
@@ -48876,7 +48899,7 @@ var ts;
48876
48899
  },
48877
48900
  getContextualTypeForObjectLiteralElement: function (nodeIn) {
48878
48901
  var node = ts.getParseTreeNode(nodeIn, ts.isObjectLiteralElementLike);
48879
- return node ? getContextualTypeForObjectLiteralElement(node) : undefined;
48902
+ return node ? getContextualTypeForObjectLiteralElement(node, /*contextFlags*/ undefined) : undefined;
48880
48903
  },
48881
48904
  getContextualTypeForArgumentAtIndex: function (nodeIn, argIndex) {
48882
48905
  var node = ts.getParseTreeNode(nodeIn, ts.isCallLikeExpression);
@@ -48884,7 +48907,7 @@ var ts;
48884
48907
  },
48885
48908
  getContextualTypeForJsxAttribute: function (nodeIn) {
48886
48909
  var node = ts.getParseTreeNode(nodeIn, ts.isJsxAttributeLike);
48887
- return node && getContextualTypeForJsxAttribute(node);
48910
+ return node && getContextualTypeForJsxAttribute(node, /*contextFlags*/ undefined);
48888
48911
  },
48889
48912
  isContextSensitive: isContextSensitive,
48890
48913
  getTypeOfPropertyOfContextualType: getTypeOfPropertyOfContextualType,
@@ -50216,6 +50239,7 @@ var ts;
50216
50239
  if (ctor && ctor.locals) {
50217
50240
  if (lookup(ctor.locals, name, meaning & 111551 /* Value */)) {
50218
50241
  // Remember the property node, it will be used later to report appropriate error
50242
+ ts.Debug.assertNode(location, ts.isPropertyDeclaration);
50219
50243
  propertyWithInvalidInitializer = location;
50220
50244
  }
50221
50245
  }
@@ -50405,11 +50429,27 @@ var ts;
50405
50429
  }
50406
50430
  }
50407
50431
  }
50432
+ // The invalid initializer error is needed in two situation:
50433
+ // 1. When result is undefined, after checking for a missing "this."
50434
+ // 2. When result is defined
50435
+ function checkAndReportErrorForInvalidInitializer() {
50436
+ if (propertyWithInvalidInitializer && !(ts.getEmitScriptTarget(compilerOptions) === 99 /* ESNext */ && useDefineForClassFields)) {
50437
+ // We have a match, but the reference occurred within a property initializer and the identifier also binds
50438
+ // to a local variable in the constructor where the code will be emitted. Note that this is actually allowed
50439
+ // with ESNext+useDefineForClassFields because the scope semantics are different.
50440
+ error(errorLocation, errorLocation && propertyWithInvalidInitializer.type && ts.textRangeContainsPositionInclusive(propertyWithInvalidInitializer.type, errorLocation.pos)
50441
+ ? ts.Diagnostics.Type_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor
50442
+ : ts.Diagnostics.Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor, ts.declarationNameToString(propertyWithInvalidInitializer.name), diagnosticName(nameArg));
50443
+ return true;
50444
+ }
50445
+ return false;
50446
+ }
50408
50447
  if (!result) {
50409
50448
  if (nameNotFoundMessage) {
50410
50449
  addLazyDiagnostic(function () {
50411
50450
  if (!errorLocation ||
50412
50451
  !checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg) && // TODO: GH#18217
50452
+ !checkAndReportErrorForInvalidInitializer() &&
50413
50453
  !checkAndReportErrorForExtendingInterface(errorLocation) &&
50414
50454
  !checkAndReportErrorForUsingTypeAsNamespace(errorLocation, name, meaning) &&
50415
50455
  !checkAndReportErrorForExportingPrimitiveType(errorLocation, name) &&
@@ -50417,7 +50457,16 @@ var ts;
50417
50457
  !checkAndReportErrorForUsingNamespaceModuleAsValue(errorLocation, name, meaning) &&
50418
50458
  !checkAndReportErrorForUsingValueAsType(errorLocation, name, meaning)) {
50419
50459
  var suggestion = void 0;
50420
- if (getSpellingSuggestions && suggestionCount < maximumSuggestionCount) {
50460
+ var suggestedLib = void 0;
50461
+ // Report missing lib first
50462
+ if (nameArg) {
50463
+ suggestedLib = getSuggestedLibForNonExistentName(nameArg);
50464
+ if (suggestedLib) {
50465
+ error(errorLocation, nameNotFoundMessage, diagnosticName(nameArg), suggestedLib);
50466
+ }
50467
+ }
50468
+ // then spelling suggestions
50469
+ if (!suggestedLib && getSpellingSuggestions && suggestionCount < maximumSuggestionCount) {
50421
50470
  suggestion = getSuggestedSymbolForNonexistentSymbol(originalLocation, name, meaning);
50422
50471
  var isGlobalScopeAugmentationDeclaration = (suggestion === null || suggestion === void 0 ? void 0 : suggestion.valueDeclaration) && ts.isAmbientModule(suggestion.valueDeclaration) && ts.isGlobalScopeAugmentation(suggestion.valueDeclaration);
50423
50472
  if (isGlobalScopeAugmentationDeclaration) {
@@ -50436,16 +50485,9 @@ var ts;
50436
50485
  }
50437
50486
  }
50438
50487
  }
50439
- if (!suggestion) {
50440
- if (nameArg) {
50441
- var lib = getSuggestedLibForNonExistentName(nameArg);
50442
- if (lib) {
50443
- error(errorLocation, nameNotFoundMessage, diagnosticName(nameArg), lib);
50444
- }
50445
- else {
50446
- error(errorLocation, nameNotFoundMessage, diagnosticName(nameArg));
50447
- }
50448
- }
50488
+ // And then fall back to unspecified "not found"
50489
+ if (!suggestion && !suggestedLib && nameArg) {
50490
+ error(errorLocation, nameNotFoundMessage, diagnosticName(nameArg));
50449
50491
  }
50450
50492
  suggestionCount++;
50451
50493
  }
@@ -50453,12 +50495,7 @@ var ts;
50453
50495
  }
50454
50496
  return undefined;
50455
50497
  }
50456
- if (propertyWithInvalidInitializer && !(ts.getEmitScriptTarget(compilerOptions) === 99 /* ESNext */ && useDefineForClassFields)) {
50457
- // We have a match, but the reference occurred within a property initializer and the identifier also binds
50458
- // to a local variable in the constructor where the code will be emitted. Note that this is actually allowed
50459
- // with ESNext+useDefineForClassFields because the scope semantics are different.
50460
- var propertyName = propertyWithInvalidInitializer.name;
50461
- error(errorLocation, ts.Diagnostics.Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor, ts.declarationNameToString(propertyName), diagnosticName(nameArg));
50498
+ else if (checkAndReportErrorForInvalidInitializer()) {
50462
50499
  return undefined;
50463
50500
  }
50464
50501
  // Perform extra checks only if error reporting was requested
@@ -52607,13 +52644,25 @@ var ts;
52607
52644
  && isDeclarationVisible(declaration.parent)) {
52608
52645
  return addVisibleAlias(declaration, declaration);
52609
52646
  }
52610
- else if (symbol.flags & 2097152 /* Alias */ && ts.isBindingElement(declaration) && ts.isInJSFile(declaration) && ((_a = declaration.parent) === null || _a === void 0 ? void 0 : _a.parent) // exported import-like top-level JS require statement
52611
- && ts.isVariableDeclaration(declaration.parent.parent)
52612
- && ((_b = declaration.parent.parent.parent) === null || _b === void 0 ? void 0 : _b.parent) && ts.isVariableStatement(declaration.parent.parent.parent.parent)
52613
- && !ts.hasSyntacticModifier(declaration.parent.parent.parent.parent, 1 /* Export */)
52614
- && declaration.parent.parent.parent.parent.parent // check if the thing containing the variable statement is visible (ie, the file)
52615
- && isDeclarationVisible(declaration.parent.parent.parent.parent.parent)) {
52616
- return addVisibleAlias(declaration, declaration.parent.parent.parent.parent);
52647
+ else if (ts.isBindingElement(declaration)) {
52648
+ if (symbol.flags & 2097152 /* Alias */ && ts.isInJSFile(declaration) && ((_a = declaration.parent) === null || _a === void 0 ? void 0 : _a.parent) // exported import-like top-level JS require statement
52649
+ && ts.isVariableDeclaration(declaration.parent.parent)
52650
+ && ((_b = declaration.parent.parent.parent) === null || _b === void 0 ? void 0 : _b.parent) && ts.isVariableStatement(declaration.parent.parent.parent.parent)
52651
+ && !ts.hasSyntacticModifier(declaration.parent.parent.parent.parent, 1 /* Export */)
52652
+ && declaration.parent.parent.parent.parent.parent // check if the thing containing the variable statement is visible (ie, the file)
52653
+ && isDeclarationVisible(declaration.parent.parent.parent.parent.parent)) {
52654
+ return addVisibleAlias(declaration, declaration.parent.parent.parent.parent);
52655
+ }
52656
+ else if (symbol.flags & 2 /* BlockScopedVariable */) {
52657
+ var variableStatement = ts.findAncestor(declaration, ts.isVariableStatement);
52658
+ if (ts.hasSyntacticModifier(variableStatement, 1 /* Export */)) {
52659
+ return true;
52660
+ }
52661
+ if (!isDeclarationVisible(variableStatement.parent)) {
52662
+ return false;
52663
+ }
52664
+ return addVisibleAlias(declaration, variableStatement);
52665
+ }
52617
52666
  }
52618
52667
  // Declaration is not visible
52619
52668
  return false;
@@ -53134,6 +53183,10 @@ var ts;
53134
53183
  }
53135
53184
  return typeToTypeNodeHelper(type, context);
53136
53185
  }
53186
+ function isHomomorphicMappedTypeWithNonHomomorphicInstantiation(type) {
53187
+ return isMappedTypeWithKeyofConstraintDeclaration(type)
53188
+ && !(getModifiersTypeFromMappedType(type).flags & 262144 /* TypeParameter */);
53189
+ }
53137
53190
  function createMappedTypeNodeFromType(type) {
53138
53191
  ts.Debug.assert(!!(type.flags & 524288 /* Object */));
53139
53192
  var readonlyToken = type.declaration.readonlyToken ? ts.factory.createToken(type.declaration.readonlyToken.kind) : undefined;
@@ -53143,7 +53196,7 @@ var ts;
53143
53196
  if (isMappedTypeWithKeyofConstraintDeclaration(type)) {
53144
53197
  // We have a { [P in keyof T]: X }
53145
53198
  // We do this to ensure we retain the toplevel keyof-ness of the type which may be lost due to keyof distribution during `getConstraintTypeFromMappedType`
53146
- if (!(getModifiersTypeFromMappedType(type).flags & 262144 /* TypeParameter */) && context.flags & 4 /* GenerateNamesForShadowedTypeParams */) {
53199
+ if (isHomomorphicMappedTypeWithNonHomomorphicInstantiation(type) && context.flags & 4 /* GenerateNamesForShadowedTypeParams */) {
53147
53200
  var newParam = createTypeParameter(createSymbol(262144 /* TypeParameter */, "T"));
53148
53201
  var name = typeParameterToName(newParam, context);
53149
53202
  newTypeVariable = ts.factory.createTypeReferenceNode(name);
@@ -53159,11 +53212,12 @@ var ts;
53159
53212
  var mappedTypeNode = ts.factory.createMappedTypeNode(readonlyToken, typeParameterNode, nameTypeNode, questionToken, templateTypeNode, /*members*/ undefined);
53160
53213
  context.approximateLength += 10;
53161
53214
  var result = ts.setEmitFlags(mappedTypeNode, 1 /* SingleLine */);
53162
- if (isMappedTypeWithKeyofConstraintDeclaration(type) && !(getModifiersTypeFromMappedType(type).flags & 262144 /* TypeParameter */) && context.flags & 4 /* GenerateNamesForShadowedTypeParams */) {
53215
+ if (isHomomorphicMappedTypeWithNonHomomorphicInstantiation(type) && context.flags & 4 /* GenerateNamesForShadowedTypeParams */) {
53163
53216
  // homomorphic mapped type with a non-homomorphic naive inlining
53164
53217
  // wrap it with a conditional like `SomeModifiersType extends infer U ? {..the mapped type...} : never` to ensure the resulting
53165
53218
  // type stays homomorphic
53166
- return ts.factory.createConditionalTypeNode(typeToTypeNodeHelper(getModifiersTypeFromMappedType(type), context), ts.factory.createInferTypeNode(ts.factory.createTypeParameterDeclaration(/*modifiers*/ undefined, ts.factory.cloneNode(newTypeVariable.typeName))), result, ts.factory.createKeywordTypeNode(143 /* NeverKeyword */));
53219
+ var originalConstraint = instantiateType(getConstraintOfTypeParameter(getTypeFromTypeNode(type.declaration.typeParameter.constraint.type)) || unknownType, type.mapper);
53220
+ return ts.factory.createConditionalTypeNode(typeToTypeNodeHelper(getModifiersTypeFromMappedType(type), context), ts.factory.createInferTypeNode(ts.factory.createTypeParameterDeclaration(/*modifiers*/ undefined, ts.factory.cloneNode(newTypeVariable.typeName), originalConstraint.flags & 2 /* Unknown */ ? undefined : typeToTypeNodeHelper(originalConstraint, context))), result, ts.factory.createKeywordTypeNode(143 /* NeverKeyword */));
53167
53221
  }
53168
53222
  return result;
53169
53223
  }
@@ -62308,19 +62362,22 @@ var ts;
62308
62362
  * to reduce the resulting type if possible (since only intersections with conflicting literal-typed properties are reducible).
62309
62363
  */
62310
62364
  function isPossiblyReducibleByInstantiation(type) {
62311
- return ts.some(type.types, function (t) {
62312
- var uniqueFilled = getUniqueLiteralFilledInstantiation(t);
62313
- return getReducedType(uniqueFilled) !== uniqueFilled;
62314
- });
62365
+ var uniqueFilled = getUniqueLiteralFilledInstantiation(type);
62366
+ return getReducedType(uniqueFilled) !== uniqueFilled;
62367
+ }
62368
+ function shouldDeferIndexType(type) {
62369
+ return !!(type.flags & 58982400 /* InstantiableNonPrimitive */ ||
62370
+ isGenericTupleType(type) ||
62371
+ isGenericMappedType(type) && !hasDistributiveNameType(type) ||
62372
+ type.flags & 1048576 /* Union */ && ts.some(type.types, isPossiblyReducibleByInstantiation) ||
62373
+ type.flags & 2097152 /* Intersection */ && maybeTypeOfKind(type, 465829888 /* Instantiable */) && ts.some(type.types, isEmptyAnonymousObjectType));
62315
62374
  }
62316
62375
  function getIndexType(type, stringsOnly, noIndexSignatures) {
62317
62376
  if (stringsOnly === void 0) { stringsOnly = keyofStringsOnly; }
62318
62377
  type = getReducedType(type);
62319
- return type.flags & 1048576 /* Union */ ? isPossiblyReducibleByInstantiation(type)
62320
- ? getIndexTypeForGenericType(type, stringsOnly)
62321
- : getIntersectionType(ts.map(type.types, function (t) { return getIndexType(t, stringsOnly, noIndexSignatures); })) :
62322
- type.flags & 2097152 /* Intersection */ ? getUnionType(ts.map(type.types, function (t) { return getIndexType(t, stringsOnly, noIndexSignatures); })) :
62323
- type.flags & 58982400 /* InstantiableNonPrimitive */ || isGenericTupleType(type) || isGenericMappedType(type) && !hasDistributiveNameType(type) ? getIndexTypeForGenericType(type, stringsOnly) :
62378
+ return shouldDeferIndexType(type) ? getIndexTypeForGenericType(type, stringsOnly) :
62379
+ type.flags & 1048576 /* Union */ ? getIntersectionType(ts.map(type.types, function (t) { return getIndexType(t, stringsOnly, noIndexSignatures); })) :
62380
+ type.flags & 2097152 /* Intersection */ ? getUnionType(ts.map(type.types, function (t) { return getIndexType(t, stringsOnly, noIndexSignatures); })) :
62324
62381
  ts.getObjectFlags(type) & 32 /* Mapped */ ? getIndexTypeForMappedType(type, stringsOnly, noIndexSignatures) :
62325
62382
  type === wildcardType ? wildcardType :
62326
62383
  type.flags & 2 /* Unknown */ ? neverType :
@@ -66113,13 +66170,20 @@ var ts;
66113
66170
  return result;
66114
66171
  }
66115
66172
  function structuredTypeRelatedTo(source, target, reportErrors, intersectionState) {
66173
+ var saveErrorInfo = captureErrorCalculationState();
66174
+ var result = structuredTypeRelatedToWorker(source, target, reportErrors, intersectionState, saveErrorInfo);
66175
+ if (result) {
66176
+ resetErrorInfo(saveErrorInfo);
66177
+ }
66178
+ return result;
66179
+ }
66180
+ function structuredTypeRelatedToWorker(source, target, reportErrors, intersectionState, saveErrorInfo) {
66116
66181
  if (intersectionState & 4 /* PropertyCheck */) {
66117
66182
  return propertiesRelatedTo(source, target, reportErrors, /*excludedProperties*/ undefined, 0 /* None */);
66118
66183
  }
66119
66184
  var result;
66120
66185
  var originalErrorInfo;
66121
66186
  var varianceCheckFailed = false;
66122
- var saveErrorInfo = captureErrorCalculationState();
66123
66187
  var sourceFlags = source.flags;
66124
66188
  var targetFlags = target.flags;
66125
66189
  if (relation === identityRelation) {
@@ -66183,7 +66247,6 @@ var ts;
66183
66247
  if (constraint && everyType(constraint, function (c) { return c !== source; })) { // Skip comparison if expansion contains the source itself
66184
66248
  // TODO: Stack errors so we get a pyramid for the "normal" comparison above, _and_ a second for this
66185
66249
  if (result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
66186
- resetErrorInfo(saveErrorInfo);
66187
66250
  return result;
66188
66251
  }
66189
66252
  }
@@ -66308,7 +66371,6 @@ var ts;
66308
66371
  result &= isRelatedTo(source.indexType, target.indexType, 3 /* Both */, reportErrors);
66309
66372
  }
66310
66373
  if (result) {
66311
- resetErrorInfo(saveErrorInfo);
66312
66374
  return result;
66313
66375
  }
66314
66376
  if (reportErrors) {
@@ -66411,7 +66473,6 @@ var ts;
66411
66473
  // If we reach 10 levels of nesting for the same conditional type, assume it is an infinitely expanding recursive
66412
66474
  // conditional type and bail out with a Ternary.Maybe result.
66413
66475
  if (isDeeplyNestedType(target, targetStack, targetDepth, 10)) {
66414
- resetErrorInfo(saveErrorInfo);
66415
66476
  return 3 /* Maybe */;
66416
66477
  }
66417
66478
  var c = target;
@@ -66426,7 +66487,6 @@ var ts;
66426
66487
  if (result = skipTrue ? -1 /* True */ : isRelatedTo(source, getTrueTypeFromConditionalType(c), 2 /* Target */, /*reportErrors*/ false)) {
66427
66488
  result &= skipFalse ? -1 /* True */ : isRelatedTo(source, getFalseTypeFromConditionalType(c), 2 /* Target */, /*reportErrors*/ false);
66428
66489
  if (result) {
66429
- resetErrorInfo(saveErrorInfo);
66430
66490
  return result;
66431
66491
  }
66432
66492
  }
@@ -66458,12 +66518,10 @@ var ts;
66458
66518
  var constraint = getConstraintOfType(source) || unknownType;
66459
66519
  // hi-speed no-this-instantiation check (less accurate, but avoids costly `this`-instantiation when the constraint will suffice), see #28231 for report on why this is needed
66460
66520
  if (result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
66461
- resetErrorInfo(saveErrorInfo);
66462
66521
  return result;
66463
66522
  }
66464
66523
  // slower, fuller, this-instantiated check (necessary when comparing raw `this` types from base classes), see `subclassWithPolymorphicThisIsAssignable.ts` test for example
66465
66524
  else if (result = isRelatedTo(getTypeWithThisArgument(constraint, source), target, 1 /* Source */, reportErrors && constraint !== unknownType && !(targetFlags & sourceFlags & 262144 /* TypeParameter */), /*headMessage*/ undefined, intersectionState)) {
66466
- resetErrorInfo(saveErrorInfo);
66467
66525
  return result;
66468
66526
  }
66469
66527
  if (isMappedTypeGenericIndexedAccess(source)) {
@@ -66472,7 +66530,6 @@ var ts;
66472
66530
  var indexConstraint = getConstraintOfType(source.indexType);
66473
66531
  if (indexConstraint) {
66474
66532
  if (result = isRelatedTo(getIndexedAccessType(source.objectType, indexConstraint), target, 1 /* Source */, reportErrors)) {
66475
- resetErrorInfo(saveErrorInfo);
66476
66533
  return result;
66477
66534
  }
66478
66535
  }
@@ -66481,7 +66538,6 @@ var ts;
66481
66538
  }
66482
66539
  else if (sourceFlags & 4194304 /* Index */) {
66483
66540
  if (result = isRelatedTo(keyofConstraintType, target, 1 /* Source */, reportErrors)) {
66484
- resetErrorInfo(saveErrorInfo);
66485
66541
  return result;
66486
66542
  }
66487
66543
  }
@@ -66489,7 +66545,6 @@ var ts;
66489
66545
  if (!(targetFlags & 134217728 /* TemplateLiteral */)) {
66490
66546
  var constraint = getBaseConstraintOfType(source);
66491
66547
  if (constraint && constraint !== source && (result = isRelatedTo(constraint, target, 1 /* Source */, reportErrors))) {
66492
- resetErrorInfo(saveErrorInfo);
66493
66548
  return result;
66494
66549
  }
66495
66550
  }
@@ -66500,14 +66555,12 @@ var ts;
66500
66555
  return 0 /* False */;
66501
66556
  }
66502
66557
  if (result = isRelatedTo(source.type, target.type, 3 /* Both */, reportErrors)) {
66503
- resetErrorInfo(saveErrorInfo);
66504
66558
  return result;
66505
66559
  }
66506
66560
  }
66507
66561
  else {
66508
66562
  var constraint = getBaseConstraintOfType(source);
66509
66563
  if (constraint && (result = isRelatedTo(constraint, target, 1 /* Source */, reportErrors))) {
66510
- resetErrorInfo(saveErrorInfo);
66511
66564
  return result;
66512
66565
  }
66513
66566
  }
@@ -66516,7 +66569,6 @@ var ts;
66516
66569
  // If we reach 10 levels of nesting for the same conditional type, assume it is an infinitely expanding recursive
66517
66570
  // conditional type and bail out with a Ternary.Maybe result.
66518
66571
  if (isDeeplyNestedType(source, sourceStack, sourceDepth, 10)) {
66519
- resetErrorInfo(saveErrorInfo);
66520
66572
  return 3 /* Maybe */;
66521
66573
  }
66522
66574
  if (targetFlags & 16777216 /* Conditional */) {
@@ -66539,7 +66591,6 @@ var ts;
66539
66591
  result &= isRelatedTo(getFalseTypeFromConditionalType(source), getFalseTypeFromConditionalType(target), 3 /* Both */, reportErrors);
66540
66592
  }
66541
66593
  if (result) {
66542
- resetErrorInfo(saveErrorInfo);
66543
66594
  return result;
66544
66595
  }
66545
66596
  }
@@ -66550,7 +66601,6 @@ var ts;
66550
66601
  var distributiveConstraint = hasNonCircularBaseConstraint(source) ? getConstraintOfDistributiveConditionalType(source) : undefined;
66551
66602
  if (distributiveConstraint) {
66552
66603
  if (result = isRelatedTo(distributiveConstraint, target, 1 /* Source */, reportErrors)) {
66553
- resetErrorInfo(saveErrorInfo);
66554
66604
  return result;
66555
66605
  }
66556
66606
  }
@@ -66560,7 +66610,6 @@ var ts;
66560
66610
  var defaultConstraint = getDefaultConstraintOfConditionalType(source);
66561
66611
  if (defaultConstraint) {
66562
66612
  if (result = isRelatedTo(defaultConstraint, target, 1 /* Source */, reportErrors)) {
66563
- resetErrorInfo(saveErrorInfo);
66564
66613
  return result;
66565
66614
  }
66566
66615
  }
@@ -66573,7 +66622,6 @@ var ts;
66573
66622
  if (isGenericMappedType(target)) {
66574
66623
  if (isGenericMappedType(source)) {
66575
66624
  if (result = mappedTypeRelatedTo(source, target, reportErrors)) {
66576
- resetErrorInfo(saveErrorInfo);
66577
66625
  return result;
66578
66626
  }
66579
66627
  }
@@ -69919,6 +69967,15 @@ var ts;
69919
69967
  var key = getFlowCacheKey(node.expression, declaredType, initialType, flowContainer);
69920
69968
  return key && key + "." + propName;
69921
69969
  }
69970
+ break;
69971
+ case 201 /* ObjectBindingPattern */:
69972
+ case 202 /* ArrayBindingPattern */:
69973
+ case 256 /* FunctionDeclaration */:
69974
+ case 213 /* FunctionExpression */:
69975
+ case 214 /* ArrowFunction */:
69976
+ case 169 /* MethodDeclaration */:
69977
+ // Handle pseudo-references originating in getNarrowedTypeOfSymbol.
69978
+ return getNodeId(node) + "#" + getTypeId(declaredType);
69922
69979
  }
69923
69980
  return undefined;
69924
69981
  }
@@ -72094,7 +72151,7 @@ var ts;
72094
72151
  !((ts.isJsxOpeningElement(node.parent) || ts.isJsxSelfClosingElement(node.parent)) && node.parent.tagName === node) &&
72095
72152
  (checkMode && checkMode & 64 /* RestBindingElement */ ?
72096
72153
  getContextualType(node, 8 /* SkipBindingPatterns */)
72097
- : getContextualType(node));
72154
+ : getContextualType(node, /*contextFlags*/ undefined));
72098
72155
  return contextualType && !isGenericType(contextualType);
72099
72156
  }
72100
72157
  function getNarrowableTypeForReference(type, reference, checkMode) {
@@ -72958,7 +73015,7 @@ var ts;
72958
73015
  // We have an object literal method. Check if the containing object literal has a contextual type
72959
73016
  // that includes a ThisType<T>. If so, T is the contextual type for 'this'. We continue looking in
72960
73017
  // any directly enclosing object literals.
72961
- var contextualType = getApparentTypeOfContextualType(containingLiteral);
73018
+ var contextualType = getApparentTypeOfContextualType(containingLiteral, /*contextFlags*/ undefined);
72962
73019
  var literal = containingLiteral;
72963
73020
  var type = contextualType;
72964
73021
  while (type) {
@@ -72970,7 +73027,7 @@ var ts;
72970
73027
  break;
72971
73028
  }
72972
73029
  literal = literal.parent.parent;
72973
- type = getApparentTypeOfContextualType(literal);
73030
+ type = getApparentTypeOfContextualType(literal, /*contextFlags*/ undefined);
72974
73031
  }
72975
73032
  // There was no contextual ThisType<T> for the containing object literal, so the contextual type
72976
73033
  // for 'this' is the non-null form of the contextual type for the containing object literal or
@@ -73027,7 +73084,7 @@ var ts;
73027
73084
  tryGetTypeAtPosition(contextualSignature, index);
73028
73085
  }
73029
73086
  }
73030
- function getContextualTypeForVariableLikeDeclaration(declaration) {
73087
+ function getContextualTypeForVariableLikeDeclaration(declaration, contextFlags) {
73031
73088
  var typeNode = ts.getEffectiveTypeAnnotationNode(declaration);
73032
73089
  if (typeNode) {
73033
73090
  return getTypeFromTypeNode(typeNode);
@@ -73036,18 +73093,18 @@ var ts;
73036
73093
  case 164 /* Parameter */:
73037
73094
  return getContextuallyTypedParameterType(declaration);
73038
73095
  case 203 /* BindingElement */:
73039
- return getContextualTypeForBindingElement(declaration);
73096
+ return getContextualTypeForBindingElement(declaration, contextFlags);
73040
73097
  case 167 /* PropertyDeclaration */:
73041
73098
  if (ts.isStatic(declaration)) {
73042
- return getContextualTypeForStaticPropertyDeclaration(declaration);
73099
+ return getContextualTypeForStaticPropertyDeclaration(declaration, contextFlags);
73043
73100
  }
73044
73101
  // By default, do nothing and return undefined - only the above cases have context implied by a parent
73045
73102
  }
73046
73103
  }
73047
- function getContextualTypeForBindingElement(declaration) {
73104
+ function getContextualTypeForBindingElement(declaration, contextFlags) {
73048
73105
  var parent = declaration.parent.parent;
73049
73106
  var name = declaration.propertyName || declaration.name;
73050
- var parentType = getContextualTypeForVariableLikeDeclaration(parent) ||
73107
+ var parentType = getContextualTypeForVariableLikeDeclaration(parent, contextFlags) ||
73051
73108
  parent.kind !== 203 /* BindingElement */ && parent.initializer && checkDeclarationInitializer(parent, declaration.dotDotDotToken ? 64 /* RestBindingElement */ : 0 /* Normal */);
73052
73109
  if (!parentType || ts.isBindingPattern(name) || ts.isComputedNonLiteralName(name))
73053
73110
  return undefined;
@@ -73063,8 +73120,8 @@ var ts;
73063
73120
  return getTypeOfPropertyOfType(parentType, text);
73064
73121
  }
73065
73122
  }
73066
- function getContextualTypeForStaticPropertyDeclaration(declaration) {
73067
- var parentType = ts.isExpression(declaration.parent) && getContextualType(declaration.parent);
73123
+ function getContextualTypeForStaticPropertyDeclaration(declaration, contextFlags) {
73124
+ var parentType = ts.isExpression(declaration.parent) && getContextualType(declaration.parent, contextFlags);
73068
73125
  if (!parentType)
73069
73126
  return undefined;
73070
73127
  return getTypeOfPropertyOfContextualType(parentType, getSymbolOfNode(declaration).escapedName);
@@ -73080,7 +73137,7 @@ var ts;
73080
73137
  function getContextualTypeForInitializerExpression(node, contextFlags) {
73081
73138
  var declaration = node.parent;
73082
73139
  if (ts.hasInitializer(declaration) && node === declaration.initializer) {
73083
- var result = getContextualTypeForVariableLikeDeclaration(declaration);
73140
+ var result = getContextualTypeForVariableLikeDeclaration(declaration, contextFlags);
73084
73141
  if (result) {
73085
73142
  return result;
73086
73143
  }
@@ -73090,10 +73147,10 @@ var ts;
73090
73147
  }
73091
73148
  return undefined;
73092
73149
  }
73093
- function getContextualTypeForReturnExpression(node) {
73150
+ function getContextualTypeForReturnExpression(node, contextFlags) {
73094
73151
  var func = ts.getContainingFunction(node);
73095
73152
  if (func) {
73096
- var contextualReturnType = getContextualReturnType(func);
73153
+ var contextualReturnType = getContextualReturnType(func, contextFlags);
73097
73154
  if (contextualReturnType) {
73098
73155
  var functionFlags = ts.getFunctionFlags(func);
73099
73156
  if (functionFlags & 1 /* Generator */) { // Generator or AsyncGenerator function
@@ -73123,11 +73180,11 @@ var ts;
73123
73180
  }
73124
73181
  return undefined;
73125
73182
  }
73126
- function getContextualTypeForYieldOperand(node) {
73183
+ function getContextualTypeForYieldOperand(node, contextFlags) {
73127
73184
  var func = ts.getContainingFunction(node);
73128
73185
  if (func) {
73129
73186
  var functionFlags = ts.getFunctionFlags(func);
73130
- var contextualReturnType = getContextualReturnType(func);
73187
+ var contextualReturnType = getContextualReturnType(func, contextFlags);
73131
73188
  if (contextualReturnType) {
73132
73189
  return node.asteriskToken
73133
73190
  ? contextualReturnType
@@ -73151,14 +73208,14 @@ var ts;
73151
73208
  }
73152
73209
  function getContextualIterationType(kind, functionDecl) {
73153
73210
  var isAsync = !!(ts.getFunctionFlags(functionDecl) & 2 /* Async */);
73154
- var contextualReturnType = getContextualReturnType(functionDecl);
73211
+ var contextualReturnType = getContextualReturnType(functionDecl, /*contextFlags*/ undefined);
73155
73212
  if (contextualReturnType) {
73156
73213
  return getIterationTypeOfGeneratorFunctionReturnType(kind, contextualReturnType, isAsync)
73157
73214
  || undefined;
73158
73215
  }
73159
73216
  return undefined;
73160
73217
  }
73161
- function getContextualReturnType(functionDecl) {
73218
+ function getContextualReturnType(functionDecl, contextFlags) {
73162
73219
  // If the containing function has a return type annotation, is a constructor, or is a get accessor whose
73163
73220
  // corresponding set accessor has a type annotation, return statements in the function are contextually typed
73164
73221
  var returnType = getReturnTypeFromAnnotation(functionDecl);
@@ -73173,7 +73230,7 @@ var ts;
73173
73230
  }
73174
73231
  var iife = ts.getImmediatelyInvokedFunctionExpression(functionDecl);
73175
73232
  if (iife) {
73176
- return getContextualType(iife);
73233
+ return getContextualType(iife, contextFlags);
73177
73234
  }
73178
73235
  return undefined;
73179
73236
  }
@@ -73426,7 +73483,7 @@ var ts;
73426
73483
  }
73427
73484
  function getContextualTypeForObjectLiteralElement(element, contextFlags) {
73428
73485
  var objectLiteral = element.parent;
73429
- var propertyAssignmentType = ts.isPropertyAssignment(element) && getContextualTypeForVariableLikeDeclaration(element);
73486
+ var propertyAssignmentType = ts.isPropertyAssignment(element) && getContextualTypeForVariableLikeDeclaration(element, contextFlags);
73430
73487
  if (propertyAssignmentType) {
73431
73488
  return propertyAssignmentType;
73432
73489
  }
@@ -73621,9 +73678,9 @@ var ts;
73621
73678
  return getContextualTypeForInitializerExpression(node, contextFlags);
73622
73679
  case 214 /* ArrowFunction */:
73623
73680
  case 247 /* ReturnStatement */:
73624
- return getContextualTypeForReturnExpression(node);
73681
+ return getContextualTypeForReturnExpression(node, contextFlags);
73625
73682
  case 224 /* YieldExpression */:
73626
- return getContextualTypeForYieldOperand(parent);
73683
+ return getContextualTypeForYieldOperand(parent, contextFlags);
73627
73684
  case 218 /* AwaitExpression */:
73628
73685
  return getContextualTypeForAwaitOperand(parent, contextFlags);
73629
73686
  case 208 /* CallExpression */:
@@ -73671,7 +73728,7 @@ var ts;
73671
73728
  }
73672
73729
  return undefined;
73673
73730
  function tryFindWhenConstTypeReference(node) {
73674
- return getContextualType(node);
73731
+ return getContextualType(node, contextFlags);
73675
73732
  }
73676
73733
  }
73677
73734
  function getInferenceContext(node) {
@@ -73973,7 +74030,7 @@ var ts;
73973
74030
  var elementCount = elements.length;
73974
74031
  var elementTypes = [];
73975
74032
  var elementFlags = [];
73976
- var contextualType = getApparentTypeOfContextualType(node);
74033
+ var contextualType = getApparentTypeOfContextualType(node, /*contextFlags*/ undefined);
73977
74034
  var inDestructuringPattern = ts.isAssignmentTarget(node);
73978
74035
  var inConstContext = isConstContext(node);
73979
74036
  var hasOmittedExpression = false;
@@ -74144,7 +74201,7 @@ var ts;
74144
74201
  var propertiesTable = ts.createSymbolTable();
74145
74202
  var propertiesArray = [];
74146
74203
  var spread = emptyObjectType;
74147
- var contextualType = getApparentTypeOfContextualType(node);
74204
+ var contextualType = getApparentTypeOfContextualType(node, /*contextFlags*/ undefined);
74148
74205
  var contextualTypeHasPattern = contextualType && contextualType.pattern &&
74149
74206
  (contextualType.pattern.kind === 201 /* ObjectBindingPattern */ || contextualType.pattern.kind === 205 /* ObjectLiteralExpression */);
74150
74207
  var inConstContext = isConstContext(node);
@@ -74483,7 +74540,7 @@ var ts;
74483
74540
  if (explicitlySpecifyChildrenAttribute) {
74484
74541
  error(attributes, ts.Diagnostics._0_are_specified_twice_The_attribute_named_0_will_be_overwritten, ts.unescapeLeadingUnderscores(jsxChildrenPropertyName));
74485
74542
  }
74486
- var contextualType = getApparentTypeOfContextualType(openingLikeElement.attributes);
74543
+ var contextualType = getApparentTypeOfContextualType(openingLikeElement.attributes, /*contextFlags*/ undefined);
74487
74544
  var childrenContextualType = contextualType && getTypeOfPropertyOfContextualType(contextualType, jsxChildrenPropertyName);
74488
74545
  // If there are children in the body of JSX element, create dummy attribute "children" with the union of children types so that it will pass the attribute checking process
74489
74546
  var childrenPropSymbol = createSymbol(4 /* Property */, jsxChildrenPropertyName);
@@ -78323,17 +78380,6 @@ var ts;
78323
78380
  }
78324
78381
  }
78325
78382
  }
78326
- var restType = getEffectiveRestType(context);
78327
- if (restType && restType.flags & 262144 /* TypeParameter */) {
78328
- // The contextual signature has a generic rest parameter. We first instantiate the contextual
78329
- // signature (without fixing type parameters) and assign types to contextually typed parameters.
78330
- var instantiatedContext = instantiateSignature(context, inferenceContext.nonFixingMapper);
78331
- assignContextualParameterTypes(signature, instantiatedContext);
78332
- // We then infer from a tuple type representing the parameters that correspond to the contextual
78333
- // rest parameter.
78334
- var restPos = getParameterCount(context) - 1;
78335
- inferTypes(inferenceContext.inferences, getRestTypeAtPosition(signature, restPos), restType);
78336
- }
78337
78383
  }
78338
78384
  function assignContextualParameterTypes(signature, context) {
78339
78385
  if (context.typeParameters) {
@@ -78526,7 +78572,7 @@ var ts;
78526
78572
  var contextualSignature = getContextualSignatureForFunctionLikeDeclaration(func);
78527
78573
  var contextualType = !contextualSignature ? undefined :
78528
78574
  contextualSignature === getSignatureFromDeclaration(func) ? isGenerator ? undefined : returnType :
78529
- instantiateContextualType(getReturnTypeOfSignature(contextualSignature), func);
78575
+ instantiateContextualType(getReturnTypeOfSignature(contextualSignature), func, /*contextFlags*/ undefined);
78530
78576
  if (isGenerator) {
78531
78577
  yieldType = getWidenedLiteralLikeTypeForContextualIterationTypeIfNeeded(yieldType, contextualType, 0 /* Yield */, isAsync);
78532
78578
  returnType = getWidenedLiteralLikeTypeForContextualIterationTypeIfNeeded(returnType, contextualType, 1 /* Return */, isAsync);
@@ -78597,7 +78643,7 @@ var ts;
78597
78643
  nextType = iterationTypes && iterationTypes.nextType;
78598
78644
  }
78599
78645
  else {
78600
- nextType = getContextualType(yieldExpression);
78646
+ nextType = getContextualType(yieldExpression, /*contextFlags*/ undefined);
78601
78647
  }
78602
78648
  if (nextType)
78603
78649
  ts.pushIfUnique(nextTypes, nextType);
@@ -78806,11 +78852,16 @@ var ts;
78806
78852
  if (isContextSensitive(node)) {
78807
78853
  if (contextualSignature) {
78808
78854
  var inferenceContext = getInferenceContext(node);
78855
+ var instantiatedContextualSignature = void 0;
78809
78856
  if (checkMode && checkMode & 2 /* Inferential */) {
78810
78857
  inferFromAnnotatedParameters(signature, contextualSignature, inferenceContext);
78858
+ var restType = getEffectiveRestType(contextualSignature);
78859
+ if (restType && restType.flags & 262144 /* TypeParameter */) {
78860
+ instantiatedContextualSignature = instantiateSignature(contextualSignature, inferenceContext.nonFixingMapper);
78861
+ }
78811
78862
  }
78812
- var instantiatedContextualSignature = inferenceContext ?
78813
- instantiateSignature(contextualSignature, inferenceContext.mapper) : contextualSignature;
78863
+ instantiatedContextualSignature || (instantiatedContextualSignature = inferenceContext ?
78864
+ instantiateSignature(contextualSignature, inferenceContext.mapper) : contextualSignature);
78814
78865
  assignContextualParameterTypes(signature, instantiatedContextualSignature);
78815
78866
  }
78816
78867
  else {
@@ -80052,7 +80103,7 @@ var ts;
80052
80103
  type = anyType;
80053
80104
  addLazyDiagnostic(function () {
80054
80105
  if (noImplicitAny && !ts.expressionResultIsUnused(node)) {
80055
- var contextualType = getContextualType(node);
80106
+ var contextualType = getContextualType(node, /*contextFlags*/ undefined);
80056
80107
  if (!contextualType || isTypeAny(contextualType)) {
80057
80108
  error(node, ts.Diagnostics.yield_expression_implicitly_results_in_an_any_type_because_its_containing_generator_lacks_a_return_type_annotation);
80058
80109
  }
@@ -80093,7 +80144,7 @@ var ts;
80093
80144
  texts.push(span.literal.text);
80094
80145
  types.push(isTypeAssignableTo(type, templateConstraintType) ? type : stringType);
80095
80146
  }
80096
- return isConstContext(node) || isTemplateLiteralContext(node) || someType(getContextualType(node) || unknownType, isTemplateLiteralContextualType) ? getTemplateLiteralType(texts, types) : stringType;
80147
+ return isConstContext(node) || isTemplateLiteralContext(node) || someType(getContextualType(node, /*contextFlags*/ undefined) || unknownType, isTemplateLiteralContextualType) ? getTemplateLiteralType(texts, types) : stringType;
80097
80148
  }
80098
80149
  function isTemplateLiteralContextualType(type) {
80099
80150
  return !!(type.flags & (128 /* StringLiteral */ | 134217728 /* TemplateLiteral */) ||
@@ -80121,7 +80172,7 @@ var ts;
80121
80172
  // We strip literal freshness when an appropriate contextual type is present such that contextually typed
80122
80173
  // literals always preserve their literal types (otherwise they might widen during type inference). An alternative
80123
80174
  // here would be to not mark contextually typed literals as fresh in the first place.
80124
- var result = maybeTypeOfKind(type, 2944 /* Literal */) && isLiteralOfContextualType(type, instantiateContextualType(contextualType, node)) ?
80175
+ var result = maybeTypeOfKind(type, 2944 /* Literal */) && isLiteralOfContextualType(type, instantiateContextualType(contextualType, node, /*contextFlags*/ undefined)) ?
80125
80176
  getRegularTypeOfLiteralType(type) : type;
80126
80177
  return result;
80127
80178
  }
@@ -80236,7 +80287,7 @@ var ts;
80236
80287
  var type = checkExpression(node, checkMode, forceTuple);
80237
80288
  return isConstContext(node) || ts.isCommonJsExportedExpression(node) ? getRegularTypeOfLiteralType(type) :
80238
80289
  isTypeAssertion(node) ? type :
80239
- getWidenedLiteralLikeTypeForContextualType(type, instantiateContextualType(arguments.length === 2 ? getContextualType(node) : contextualType, node));
80290
+ getWidenedLiteralLikeTypeForContextualType(type, instantiateContextualType(arguments.length === 2 ? getContextualType(node, /*contextFlags*/ undefined) : contextualType, node, /*contextFlags*/ undefined));
80240
80291
  }
80241
80292
  function checkPropertyAssignment(node, checkMode) {
80242
80293
  // Do not use hasDynamicName here, because that returns false for well known symbols.