typescript 4.7.0-dev.20220215 → 4.7.0-dev.20220216

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/tsserver.js CHANGED
@@ -100,7 +100,7 @@ var ts;
100
100
  // The following is baselined as a literal template type without intervention
101
101
  /** The version of the TypeScript compiler release */
102
102
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
103
- ts.version = ts.versionMajorMinor + ".0-dev.20220215";
103
+ ts.version = ts.versionMajorMinor + ".0-dev.20220216";
104
104
  /* @internal */
105
105
  var Comparison;
106
106
  (function (Comparison) {
@@ -4840,6 +4840,8 @@ var ts;
4840
4840
  TypeFlags[TypeFlags["ESSymbolLike"] = 12288] = "ESSymbolLike";
4841
4841
  TypeFlags[TypeFlags["VoidLike"] = 49152] = "VoidLike";
4842
4842
  /* @internal */
4843
+ TypeFlags[TypeFlags["DefinitelyNonNullable"] = 470302716] = "DefinitelyNonNullable";
4844
+ /* @internal */
4843
4845
  TypeFlags[TypeFlags["DisjointDomains"] = 469892092] = "DisjointDomains";
4844
4846
  TypeFlags[TypeFlags["UnionOrIntersection"] = 3145728] = "UnionOrIntersection";
4845
4847
  TypeFlags[TypeFlags["StructuredType"] = 3670016] = "StructuredType";
@@ -5572,6 +5574,8 @@ var ts;
5572
5574
  BundleFileSectionKind["NoDefaultLib"] = "no-default-lib";
5573
5575
  BundleFileSectionKind["Reference"] = "reference";
5574
5576
  BundleFileSectionKind["Type"] = "type";
5577
+ BundleFileSectionKind["TypeResolutionModeRequire"] = "type-require";
5578
+ BundleFileSectionKind["TypeResolutionModeImport"] = "type-import";
5575
5579
  BundleFileSectionKind["Lib"] = "lib";
5576
5580
  BundleFileSectionKind["Prepend"] = "prepend";
5577
5581
  BundleFileSectionKind["Text"] = "text";
@@ -5688,7 +5692,8 @@ var ts;
5688
5692
  { name: "types", optional: true, captureSpan: true },
5689
5693
  { name: "lib", optional: true, captureSpan: true },
5690
5694
  { name: "path", optional: true, captureSpan: true },
5691
- { name: "no-default-lib", optional: true }
5695
+ { name: "no-default-lib", optional: true },
5696
+ { name: "resolution-mode", optional: true }
5692
5697
  ],
5693
5698
  kind: 1 /* TripleSlashXML */
5694
5699
  },
@@ -8069,6 +8074,8 @@ var ts;
8069
8074
  Property_0_cannot_have_an_initializer_because_it_is_marked_abstract: diag(1267, ts.DiagnosticCategory.Error, "Property_0_cannot_have_an_initializer_because_it_is_marked_abstract_1267", "Property '{0}' cannot have an initializer because it is marked abstract."),
8070
8075
  An_index_signature_parameter_type_must_be_string_number_symbol_or_a_template_literal_type: diag(1268, ts.DiagnosticCategory.Error, "An_index_signature_parameter_type_must_be_string_number_symbol_or_a_template_literal_type_1268", "An index signature parameter type must be 'string', 'number', 'symbol', or a template literal type."),
8071
8076
  Cannot_use_export_import_on_a_type_or_type_only_namespace_when_the_isolatedModules_flag_is_provided: diag(1269, ts.DiagnosticCategory.Error, "Cannot_use_export_import_on_a_type_or_type_only_namespace_when_the_isolatedModules_flag_is_provided_1269", "Cannot use 'export import' on a type or type-only namespace when the '--isolatedModules' flag is provided."),
8077
+ Decorator_function_return_type_0_is_not_assignable_to_type_1: diag(1270, ts.DiagnosticCategory.Error, "Decorator_function_return_type_0_is_not_assignable_to_type_1_1270", "Decorator function return type '{0}' is not assignable to type '{1}'."),
8078
+ Decorator_function_return_type_is_0_but_is_expected_to_be_void_or_any: diag(1271, ts.DiagnosticCategory.Error, "Decorator_function_return_type_is_0_but_is_expected_to_be_void_or_any_1271", "Decorator function return type is '{0}' but is expected to be 'void' or 'any'."),
8072
8079
  with_statements_are_not_allowed_in_an_async_function_block: diag(1300, ts.DiagnosticCategory.Error, "with_statements_are_not_allowed_in_an_async_function_block_1300", "'with' statements are not allowed in an async function block."),
8073
8080
  await_expressions_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules: diag(1308, ts.DiagnosticCategory.Error, "await_expressions_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules_1308", "'await' expressions are only allowed within async functions and at the top levels of modules."),
8074
8081
  Did_you_mean_to_use_a_Colon_An_can_only_follow_a_property_name_when_the_containing_object_literal_is_part_of_a_destructuring_pattern: diag(1312, ts.DiagnosticCategory.Error, "Did_you_mean_to_use_a_Colon_An_can_only_follow_a_property_name_when_the_containing_object_literal_is_1312", "Did you mean to use a ':'? An '=' can only follow a property name when the containing object literal is part of a destructuring pattern."),
@@ -8202,6 +8209,8 @@ var ts;
8202
8209
  Preserve_unused_imported_values_in_the_JavaScript_output_that_would_otherwise_be_removed: diag(1449, ts.DiagnosticCategory.Message, "Preserve_unused_imported_values_in_the_JavaScript_output_that_would_otherwise_be_removed_1449", "Preserve unused imported values in the JavaScript output that would otherwise be removed."),
8203
8210
  Dynamic_imports_can_only_accept_a_module_specifier_and_an_optional_assertion_as_arguments: diag(1450, ts.DiagnosticCategory.Message, "Dynamic_imports_can_only_accept_a_module_specifier_and_an_optional_assertion_as_arguments_1450", "Dynamic imports can only accept a module specifier and an optional assertion as arguments"),
8204
8211
  Private_identifiers_are_only_allowed_in_class_bodies_and_may_only_be_used_as_part_of_a_class_member_declaration_property_access_or_on_the_left_hand_side_of_an_in_expression: diag(1451, ts.DiagnosticCategory.Error, "Private_identifiers_are_only_allowed_in_class_bodies_and_may_only_be_used_as_part_of_a_class_member__1451", "Private identifiers are only allowed in class bodies and may only be used as part of a class member declaration, property access, or on the left-hand-side of an 'in' expression"),
8212
+ Resolution_modes_are_only_supported_when_moduleResolution_is_node12_or_nodenext: diag(1452, ts.DiagnosticCategory.Error, "Resolution_modes_are_only_supported_when_moduleResolution_is_node12_or_nodenext_1452", "Resolution modes are only supported when `moduleResolution` is `node12` or `nodenext`."),
8213
+ resolution_mode_should_be_either_require_or_import: diag(1453, ts.DiagnosticCategory.Error, "resolution_mode_should_be_either_require_or_import_1453", "`resolution-mode` should be either `require` or `import`."),
8205
8214
  The_import_meta_meta_property_is_not_allowed_in_files_which_will_build_into_CommonJS_output: diag(1470, ts.DiagnosticCategory.Error, "The_import_meta_meta_property_is_not_allowed_in_files_which_will_build_into_CommonJS_output_1470", "The 'import.meta' meta-property is not allowed in files which will build into CommonJS output."),
8206
8215
  Module_0_cannot_be_imported_using_this_construct_The_specifier_only_resolves_to_an_ES_module_which_cannot_be_imported_synchronously_Use_dynamic_import_instead: diag(1471, ts.DiagnosticCategory.Error, "Module_0_cannot_be_imported_using_this_construct_The_specifier_only_resolves_to_an_ES_module_which_c_1471", "Module '{0}' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead."),
8207
8216
  catch_or_finally_expected: diag(1472, ts.DiagnosticCategory.Error, "catch_or_finally_expected_1472", "'catch' or 'finally' expected."),
@@ -14085,7 +14094,11 @@ var ts;
14085
14094
  ts.Debug.assert(names.length === newResolutions.length);
14086
14095
  for (var i = 0; i < names.length; i++) {
14087
14096
  var newResolution = newResolutions[i];
14088
- var oldResolution = oldResolutions && oldResolutions.get(names[i], oldSourceFile && ts.getModeForResolutionAtIndex(oldSourceFile, i));
14097
+ var entry = names[i];
14098
+ // We lower-case all type references because npm automatically lowercases all packages. See GH#9824.
14099
+ var name = !ts.isString(entry) ? entry.fileName.toLowerCase() : entry;
14100
+ var mode = !ts.isString(entry) ? ts.getModeForFileReference(entry, oldSourceFile === null || oldSourceFile === void 0 ? void 0 : oldSourceFile.impliedNodeFormat) : oldSourceFile && ts.getModeForResolutionAtIndex(oldSourceFile, i);
14101
+ var oldResolution = oldResolutions && oldResolutions.get(name, mode);
14089
14102
  var changed = oldResolution
14090
14103
  ? !newResolution || !comparer(oldResolution, newResolution)
14091
14104
  : newResolution;
@@ -26680,7 +26693,13 @@ var ts;
26680
26693
  referencedFiles = ts.append(referencedFiles, { pos: -1, end: -1, fileName: section.data });
26681
26694
  break;
26682
26695
  case "type" /* Type */:
26683
- typeReferenceDirectives = ts.append(typeReferenceDirectives, section.data);
26696
+ typeReferenceDirectives = ts.append(typeReferenceDirectives, { pos: -1, end: -1, fileName: section.data });
26697
+ break;
26698
+ case "type-import" /* TypeResolutionModeImport */:
26699
+ typeReferenceDirectives = ts.append(typeReferenceDirectives, { pos: -1, end: -1, fileName: section.data, resolutionMode: ts.ModuleKind.ESNext });
26700
+ break;
26701
+ case "type-require" /* TypeResolutionModeRequire */:
26702
+ typeReferenceDirectives = ts.append(typeReferenceDirectives, { pos: -1, end: -1, fileName: section.data, resolutionMode: ts.ModuleKind.CommonJS });
26684
26703
  break;
26685
26704
  case "lib" /* Lib */:
26686
26705
  libReferenceDirectives = ts.append(libReferenceDirectives, { pos: -1, end: -1, fileName: section.data });
@@ -26739,6 +26758,8 @@ var ts;
26739
26758
  case "no-default-lib" /* NoDefaultLib */:
26740
26759
  case "reference" /* Reference */:
26741
26760
  case "type" /* Type */:
26761
+ case "type-import" /* TypeResolutionModeImport */:
26762
+ case "type-require" /* TypeResolutionModeRequire */:
26742
26763
  case "lib" /* Lib */:
26743
26764
  syntheticReferences = ts.append(syntheticReferences, ts.setTextRange(ts.factory.createUnparsedSyntheticReference(section), section));
26744
26765
  break;
@@ -30652,7 +30673,7 @@ var ts;
30652
30673
  initializeState("", content, languageVersion, /*syntaxCursor*/ undefined, 1 /* JS */);
30653
30674
  // Prime the scanner.
30654
30675
  nextToken();
30655
- var entityName = parseEntityName(/*allowReservedWords*/ true);
30676
+ var entityName = parseEntityName(/*allowReservedWords*/ true, /*allowPrivateIdentifiers*/ false);
30656
30677
  var isInvalid = token() === 1 /* EndOfFileToken */ && !parseDiagnostics.length;
30657
30678
  clearState();
30658
30679
  return isInvalid ? entityName : undefined;
@@ -32229,7 +32250,7 @@ var ts;
32229
32250
  }
32230
32251
  return createMissingList();
32231
32252
  }
32232
- function parseEntityName(allowReservedWords, diagnosticMessage) {
32253
+ function parseEntityName(allowReservedWords, allowPrivateIdentifiers, diagnosticMessage) {
32233
32254
  var pos = getNodePos();
32234
32255
  var entity = allowReservedWords ? parseIdentifierName(diagnosticMessage) : parseIdentifier(diagnosticMessage);
32235
32256
  var dotPos = getNodePos();
@@ -32240,7 +32261,7 @@ var ts;
32240
32261
  break;
32241
32262
  }
32242
32263
  dotPos = getNodePos();
32243
- entity = finishNode(factory.createQualifiedName(entity, parseRightSideOfDot(allowReservedWords, /* allowPrivateIdentifiers */ false)), pos);
32264
+ entity = finishNode(factory.createQualifiedName(entity, parseRightSideOfDot(allowReservedWords, allowPrivateIdentifiers)), pos);
32244
32265
  }
32245
32266
  return entity;
32246
32267
  }
@@ -32373,7 +32394,7 @@ var ts;
32373
32394
  }
32374
32395
  // TYPES
32375
32396
  function parseEntityNameOfTypeReference() {
32376
- return parseEntityName(/*allowReservedWords*/ true, ts.Diagnostics.Type_expected);
32397
+ return parseEntityName(/*allowReservedWords*/ true, /*allowPrivateIdentifiers*/ false, ts.Diagnostics.Type_expected);
32377
32398
  }
32378
32399
  function parseTypeArgumentsOfTypeReference() {
32379
32400
  if (!scanner.hasPrecedingLineBreak() && reScanLessThanToken() === 29 /* LessThanToken */) {
@@ -32506,7 +32527,7 @@ var ts;
32506
32527
  function parseTypeQuery() {
32507
32528
  var pos = getNodePos();
32508
32529
  parseExpected(112 /* TypeOfKeyword */);
32509
- return finishNode(factory.createTypeQueryNode(parseEntityName(/*allowReservedWords*/ true)), pos);
32530
+ return finishNode(factory.createTypeQueryNode(parseEntityName(/*allowReservedWords*/ true, /*allowPrivateIdentifiers*/ true)), pos);
32510
32531
  }
32511
32532
  function parseTypeParameter() {
32512
32533
  var pos = getNodePos();
@@ -35077,11 +35098,12 @@ var ts;
35077
35098
  }
35078
35099
  function parseCaseClause() {
35079
35100
  var pos = getNodePos();
35101
+ var hasJSDoc = hasPrecedingJSDocComment();
35080
35102
  parseExpected(82 /* CaseKeyword */);
35081
35103
  var expression = allowInAnd(parseExpression);
35082
35104
  parseExpected(58 /* ColonToken */);
35083
35105
  var statements = parseList(3 /* SwitchClauseStatements */, parseStatement);
35084
- return finishNode(factory.createCaseClause(expression, statements), pos);
35106
+ return withJSDoc(finishNode(factory.createCaseClause(expression, statements), pos), hasJSDoc);
35085
35107
  }
35086
35108
  function parseDefaultClause() {
35087
35109
  var pos = getNodePos();
@@ -36244,7 +36266,7 @@ var ts;
36244
36266
  function parseModuleReference() {
36245
36267
  return isExternalModuleReference()
36246
36268
  ? parseExternalModuleReference()
36247
- : parseEntityName(/*allowReservedWords*/ false);
36269
+ : parseEntityName(/*allowReservedWords*/ false, /*allowPrivateIdentifiers*/ false);
36248
36270
  }
36249
36271
  function parseExternalModuleReference() {
36250
36272
  var pos = getNodePos();
@@ -36526,7 +36548,7 @@ var ts;
36526
36548
  var pos = getNodePos();
36527
36549
  var hasBrace = parseOptional(18 /* OpenBraceToken */);
36528
36550
  var p2 = getNodePos();
36529
- var entityName = parseEntityName(/* allowReservedWords*/ false);
36551
+ var entityName = parseEntityName(/* allowReservedWords*/ false, /*allowPrivateIdentifiers*/ false);
36530
36552
  while (token() === 80 /* PrivateIdentifier */) {
36531
36553
  reScanHashToken(); // rescan #id as # id
36532
36554
  nextTokenJSDoc(); // then skip the #
@@ -36969,7 +36991,7 @@ var ts;
36969
36991
  // parseEntityName logs an error for non-identifier, so create a MissingNode ourselves to avoid the error
36970
36992
  var p2 = getNodePos();
36971
36993
  var name = ts.tokenIsIdentifierOrKeyword(token())
36972
- ? parseEntityName(/*allowReservedWords*/ true)
36994
+ ? parseEntityName(/*allowReservedWords*/ true, /*allowPrivateIdentifiers*/ false)
36973
36995
  : undefined;
36974
36996
  if (name) {
36975
36997
  while (token() === 80 /* PrivateIdentifier */) {
@@ -36994,11 +37016,13 @@ var ts;
36994
37016
  && nextTokenJSDoc() === 59 /* AtToken */
36995
37017
  && ts.tokenIsIdentifierOrKeyword(nextTokenJSDoc())) {
36996
37018
  var kind = scanner.getTokenValue();
36997
- if (kind === "link" || kind === "linkcode" || kind === "linkplain") {
37019
+ if (isJSDocLinkTag(kind))
36998
37020
  return kind;
36999
- }
37000
37021
  }
37001
37022
  }
37023
+ function isJSDocLinkTag(kind) {
37024
+ return kind === "link" || kind === "linkcode" || kind === "linkplain";
37025
+ }
37002
37026
  function parseUnknownTag(start, tagName, indent, indentText) {
37003
37027
  return finishNode(factory.createJSDocUnknownTag(tagName, parseTrailingTagComments(start, getNodePos(), indent, indentText)), start);
37004
37028
  }
@@ -37104,7 +37128,7 @@ var ts;
37104
37128
  }
37105
37129
  function parseSeeTag(start, tagName, indent, indentText) {
37106
37130
  var isMarkdownOrJSDocLink = token() === 22 /* OpenBracketToken */
37107
- || lookAhead(function () { return nextTokenJSDoc() === 59 /* AtToken */ && ts.tokenIsIdentifierOrKeyword(nextTokenJSDoc()) && scanner.getTokenValue() === "link"; });
37131
+ || lookAhead(function () { return nextTokenJSDoc() === 59 /* AtToken */ && ts.tokenIsIdentifierOrKeyword(nextTokenJSDoc()) && isJSDocLinkTag(scanner.getTokenValue()); });
37108
37132
  var nameExpression = isMarkdownOrJSDocLink ? undefined : parseJSDocNameReference();
37109
37133
  var comments = indent !== undefined && indentText !== undefined ? parseTrailingTagComments(start, getNodePos(), indent, indentText) : undefined;
37110
37134
  return finishNode(factory.createJSDocSeeTag(tagName, nameExpression, comments), start);
@@ -37971,6 +37995,19 @@ var ts;
37971
37995
  return ts.fileExtensionIsOneOf(fileName, [".d.ts" /* Dts */, ".d.mts" /* Dmts */, ".d.cts" /* Dcts */]);
37972
37996
  }
37973
37997
  ts.isDeclarationFileName = isDeclarationFileName;
37998
+ function parseResolutionMode(mode, pos, end, reportDiagnostic) {
37999
+ if (!mode) {
38000
+ return undefined;
38001
+ }
38002
+ if (mode === "import") {
38003
+ return ts.ModuleKind.ESNext;
38004
+ }
38005
+ if (mode === "require") {
38006
+ return ts.ModuleKind.CommonJS;
38007
+ }
38008
+ reportDiagnostic(pos, end - pos, ts.Diagnostics.resolution_mode_should_be_either_require_or_import);
38009
+ return undefined;
38010
+ }
37974
38011
  /*@internal*/
37975
38012
  function processCommentPragmas(context, sourceText) {
37976
38013
  var pragmas = [];
@@ -38013,12 +38050,13 @@ var ts;
38013
38050
  var typeReferenceDirectives_1 = context.typeReferenceDirectives;
38014
38051
  var libReferenceDirectives_1 = context.libReferenceDirectives;
38015
38052
  ts.forEach(ts.toArray(entryOrList), function (arg) {
38016
- var _a = arg.arguments, types = _a.types, lib = _a.lib, path = _a.path;
38053
+ var _a = arg.arguments, types = _a.types, lib = _a.lib, path = _a.path, res = _a["resolution-mode"];
38017
38054
  if (arg.arguments["no-default-lib"]) {
38018
38055
  context.hasNoDefaultLib = true;
38019
38056
  }
38020
38057
  else if (types) {
38021
- typeReferenceDirectives_1.push({ pos: types.pos, end: types.end, fileName: types.value });
38058
+ var parsed = parseResolutionMode(res, types.pos, types.end, reportDiagnostic);
38059
+ typeReferenceDirectives_1.push(__assign({ pos: types.pos, end: types.end, fileName: types.value }, (parsed ? { resolutionMode: parsed } : {})));
38022
38060
  }
38023
38061
  else if (lib) {
38024
38062
  libReferenceDirectives_1.push({ pos: lib.pos, end: lib.end, fileName: lib.value });
@@ -41596,14 +41634,14 @@ var ts;
41596
41634
  * This is possible in case if resolution is performed for directives specified via 'types' parameter. In this case initial path for secondary lookups
41597
41635
  * is assumed to be the same as root directory of the project.
41598
41636
  */
41599
- function resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference, cache) {
41637
+ function resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference, cache, resolutionMode) {
41600
41638
  var traceEnabled = isTraceEnabled(options, host);
41601
41639
  if (redirectedReference) {
41602
41640
  options = redirectedReference.commandLine.options;
41603
41641
  }
41604
41642
  var containingDirectory = containingFile ? ts.getDirectoryPath(containingFile) : undefined;
41605
41643
  var perFolderCache = containingDirectory ? cache && cache.getOrCreateCacheForDirectory(containingDirectory, redirectedReference) : undefined;
41606
- var result = perFolderCache && perFolderCache.get(typeReferenceDirectiveName, /*mode*/ undefined);
41644
+ var result = perFolderCache && perFolderCache.get(typeReferenceDirectiveName, /*mode*/ resolutionMode);
41607
41645
  if (result) {
41608
41646
  if (traceEnabled) {
41609
41647
  trace(host, ts.Diagnostics.Resolving_type_reference_directive_0_containing_file_1, typeReferenceDirectiveName, containingFile);
@@ -41638,7 +41676,18 @@ var ts;
41638
41676
  }
41639
41677
  var failedLookupLocations = [];
41640
41678
  var features = getDefaultNodeResolutionFeatures(options);
41641
- var moduleResolutionState = { compilerOptions: options, host: host, traceEnabled: traceEnabled, failedLookupLocations: failedLookupLocations, packageJsonInfoCache: cache, features: features, conditions: ["node", "require", "types"] };
41679
+ // Unlike `import` statements, whose mode-calculating APIs are all guaranteed to return `undefined` if we're in an un-mode-ed module resolution
41680
+ // setting, type references will return their target mode regardless of options because of how the parser works, so we guard against the mode being
41681
+ // set in a non-modal module resolution setting here. Do note that our behavior is not particularly well defined when these mode-overriding imports
41682
+ // are present in a non-modal project; while in theory we'd like to either ignore the mode or provide faithful modern resolution, depending on what we feel is best,
41683
+ // in practice, not every cache has the options available to intelligently make the choice to ignore the mode request, and it's unclear how modern "faithful modern
41684
+ // resolution" should be (`node12`? `nodenext`?). As such, witnessing a mode-overriding triple-slash reference in a non-modal module resolution
41685
+ // context should _probably_ be an error - and that should likely be handled by the `Program` (which is what we do).
41686
+ if (resolutionMode === ts.ModuleKind.ESNext && (ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Node12 || ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext)) {
41687
+ features |= NodeResolutionFeatures.EsmMode;
41688
+ }
41689
+ var conditions = features & NodeResolutionFeatures.Exports ? features & NodeResolutionFeatures.EsmMode ? ["node", "import", "types"] : ["node", "require", "types"] : [];
41690
+ var moduleResolutionState = { compilerOptions: options, host: host, traceEnabled: traceEnabled, failedLookupLocations: failedLookupLocations, packageJsonInfoCache: cache, features: features, conditions: conditions };
41642
41691
  var resolved = primaryLookup();
41643
41692
  var primary = true;
41644
41693
  if (!resolved) {
@@ -41658,7 +41707,7 @@ var ts;
41658
41707
  };
41659
41708
  }
41660
41709
  result = { resolvedTypeReferenceDirective: resolvedTypeReferenceDirective, failedLookupLocations: failedLookupLocations };
41661
- perFolderCache === null || perFolderCache === void 0 ? void 0 : perFolderCache.set(typeReferenceDirectiveName, /*mode*/ undefined, result);
41710
+ perFolderCache === null || perFolderCache === void 0 ? void 0 : perFolderCache.set(typeReferenceDirectiveName, /*mode*/ resolutionMode, result);
41662
41711
  if (traceEnabled)
41663
41712
  traceResult(result);
41664
41713
  return result;
@@ -41944,7 +41993,11 @@ var ts;
41944
41993
  ts.Debug.assert(keys.length === values.length);
41945
41994
  var map = createModeAwareCache();
41946
41995
  for (var i = 0; i < keys.length; ++i) {
41947
- map.set(keys[i], ts.getModeForResolutionAtIndex(file, i), values[i]);
41996
+ var entry = keys[i];
41997
+ // We lower-case all type references because npm automatically lowercases all packages. See GH#9824.
41998
+ var name = !ts.isString(entry) ? entry.fileName.toLowerCase() : entry;
41999
+ var mode = !ts.isString(entry) ? entry.resolutionMode || file.impliedNodeFormat : ts.getModeForResolutionAtIndex(file, i);
42000
+ map.set(name, mode, values[i]);
41948
42001
  }
41949
42002
  return map;
41950
42003
  }
@@ -46964,8 +47017,7 @@ var ts;
46964
47017
  IntersectionState[IntersectionState["Source"] = 1] = "Source";
46965
47018
  IntersectionState[IntersectionState["Target"] = 2] = "Target";
46966
47019
  IntersectionState[IntersectionState["PropertyCheck"] = 4] = "PropertyCheck";
46967
- IntersectionState[IntersectionState["UnionIntersectionCheck"] = 8] = "UnionIntersectionCheck";
46968
- IntersectionState[IntersectionState["InPropertyCheck"] = 16] = "InPropertyCheck";
47020
+ IntersectionState[IntersectionState["InPropertyCheck"] = 8] = "InPropertyCheck";
46969
47021
  })(IntersectionState || (IntersectionState = {}));
46970
47022
  var RecursionFlags;
46971
47023
  (function (RecursionFlags) {
@@ -58686,13 +58738,15 @@ var ts;
58686
58738
  return signature;
58687
58739
  }
58688
58740
  function getOrCreateTypeFromSignature(signature) {
58741
+ var _a;
58689
58742
  // There are two ways to declare a construct signature, one is by declaring a class constructor
58690
58743
  // using the constructor keyword, and the other is declaring a bare construct signature in an
58691
58744
  // object type literal or interface (using the new keyword). Each way of declaring a constructor
58692
58745
  // will result in a different declaration kind.
58693
58746
  if (!signature.isolatedSignatureType) {
58694
- var kind = signature.declaration ? signature.declaration.kind : 0 /* Unknown */;
58695
- var isConstructor = kind === 170 /* Constructor */ || kind === 174 /* ConstructSignature */ || kind === 179 /* ConstructorType */;
58747
+ var kind = (_a = signature.declaration) === null || _a === void 0 ? void 0 : _a.kind;
58748
+ // If declaration is undefined, it is likely to be the signature of the default constructor.
58749
+ var isConstructor = kind === undefined || kind === 170 /* Constructor */ || kind === 174 /* ConstructSignature */ || kind === 179 /* ConstructorType */;
58696
58750
  var type = createObjectType(16 /* Anonymous */);
58697
58751
  type.members = emptySymbols;
58698
58752
  type.properties = ts.emptyArray;
@@ -59620,7 +59674,7 @@ var ts;
59620
59674
  }
59621
59675
  }
59622
59676
  var fixedLength = properties.length;
59623
- var lengthSymbol = createSymbol(4 /* Property */, "length");
59677
+ var lengthSymbol = createSymbol(4 /* Property */, "length", readonly ? 8 /* Readonly */ : 0);
59624
59678
  if (combinedFlags & 12 /* Variable */) {
59625
59679
  lengthSymbol.type = numberType;
59626
59680
  }
@@ -63260,11 +63314,11 @@ var ts;
63260
63314
  var overflow = false;
63261
63315
  var overrideNextErrorInfo = 0; // How many `reportRelationError` calls should be skipped in the elaboration pyramid
63262
63316
  var lastSkippedInfo;
63263
- var incompatibleStack = [];
63317
+ var incompatibleStack;
63264
63318
  var inPropertyCheck = false;
63265
63319
  ts.Debug.assert(relation !== identityRelation || !errorNode, "no error reporting in identity checking");
63266
63320
  var result = isRelatedTo(source, target, 3 /* Both */, /*reportErrors*/ !!errorNode, headMessage);
63267
- if (incompatibleStack.length) {
63321
+ if (incompatibleStack) {
63268
63322
  reportIncompatibleStack();
63269
63323
  }
63270
63324
  if (overflow) {
@@ -63321,19 +63375,19 @@ var ts;
63321
63375
  return {
63322
63376
  errorInfo: errorInfo,
63323
63377
  lastSkippedInfo: lastSkippedInfo,
63324
- incompatibleStack: incompatibleStack.slice(),
63378
+ incompatibleStack: incompatibleStack === null || incompatibleStack === void 0 ? void 0 : incompatibleStack.slice(),
63325
63379
  overrideNextErrorInfo: overrideNextErrorInfo,
63326
- relatedInfo: !relatedInfo ? undefined : relatedInfo.slice()
63380
+ relatedInfo: relatedInfo === null || relatedInfo === void 0 ? void 0 : relatedInfo.slice(),
63327
63381
  };
63328
63382
  }
63329
63383
  function reportIncompatibleError(message, arg0, arg1, arg2, arg3) {
63330
63384
  overrideNextErrorInfo++; // Suppress the next relation error
63331
63385
  lastSkippedInfo = undefined; // Reset skipped info cache
63332
- incompatibleStack.push([message, arg0, arg1, arg2, arg3]);
63386
+ (incompatibleStack || (incompatibleStack = [])).push([message, arg0, arg1, arg2, arg3]);
63333
63387
  }
63334
63388
  function reportIncompatibleStack() {
63335
- var stack = incompatibleStack;
63336
- incompatibleStack = [];
63389
+ var stack = incompatibleStack || [];
63390
+ incompatibleStack = undefined;
63337
63391
  var info = lastSkippedInfo;
63338
63392
  lastSkippedInfo = undefined;
63339
63393
  if (stack.length === 1) {
@@ -63439,7 +63493,7 @@ var ts;
63439
63493
  }
63440
63494
  function reportError(message, arg0, arg1, arg2, arg3) {
63441
63495
  ts.Debug.assert(!!errorNode);
63442
- if (incompatibleStack.length)
63496
+ if (incompatibleStack)
63443
63497
  reportIncompatibleStack();
63444
63498
  if (message.elidedInCompatabilityPyramid)
63445
63499
  return;
@@ -63455,7 +63509,7 @@ var ts;
63455
63509
  }
63456
63510
  }
63457
63511
  function reportRelationError(message, source, target) {
63458
- if (incompatibleStack.length)
63512
+ if (incompatibleStack)
63459
63513
  reportIncompatibleStack();
63460
63514
  var _a = getTypeNamesForErrorDisplay(source, target), sourceType = _a[0], targetType = _a[1];
63461
63515
  var generalizedSource = source;
@@ -63567,7 +63621,9 @@ var ts;
63567
63621
  if (isSimpleTypeRelatedTo(originalSource, originalTarget, relation, reportErrors ? reportError : undefined)) {
63568
63622
  return -1 /* True */;
63569
63623
  }
63570
- reportErrorResults(originalSource, originalTarget, 0 /* False */, !!(ts.getObjectFlags(originalSource) & 2048 /* JsxAttributes */));
63624
+ if (reportErrors) {
63625
+ reportErrorResults(originalSource, originalTarget, originalSource, originalTarget, headMessage);
63626
+ }
63571
63627
  return 0 /* False */;
63572
63628
  }
63573
63629
  // Normalize the source and target types: Turn fresh literal types into regular literal types,
@@ -63579,7 +63635,12 @@ var ts;
63579
63635
  if (source === target)
63580
63636
  return -1 /* True */;
63581
63637
  if (relation === identityRelation) {
63582
- return isIdenticalTo(source, target, recursionFlags);
63638
+ if (source.flags !== target.flags)
63639
+ return 0 /* False */;
63640
+ if (source.flags & 67358815 /* Singleton */)
63641
+ return -1 /* True */;
63642
+ traceUnionsOrIntersectionsTooLarge(source, target);
63643
+ return recursiveTypeRelatedTo(source, target, /*reportErrors*/ false, 0 /* None */, recursionFlags);
63583
63644
  }
63584
63645
  // We fastpath comparing a type parameter to exactly its constraint, as this is _super_ common,
63585
63646
  // and otherwise, for type parameters in large unions, causes us to need to compare the union to itself,
@@ -63589,163 +63650,130 @@ var ts;
63589
63650
  if (source.flags & 262144 /* TypeParameter */ && getConstraintOfType(source) === target) {
63590
63651
  return -1 /* True */;
63591
63652
  }
63592
- // Try to see if we're relating something like `Foo` -> `Bar | null | undefined`.
63593
- // If so, reporting the `null` and `undefined` in the type is hardly useful.
63594
- // First, see if we're even relating an object type to a union.
63595
- // Then see if the target is stripped down to a single non-union type.
63596
- // Note
63597
- // * We actually want to remove null and undefined naively here (rather than using getNonNullableType),
63598
- // since we don't want to end up with a worse error like "`Foo` is not assignable to `NonNullable<T>`"
63599
- // when dealing with generics.
63600
- // * We also don't deal with primitive source types, since we already halt elaboration below.
63601
- if (target.flags & 1048576 /* Union */ && source.flags & 524288 /* Object */ &&
63602
- target.types.length <= 3 && maybeTypeOfKind(target, 98304 /* Nullable */)) {
63603
- var nullStrippedTarget = extractTypesOfKind(target, ~98304 /* Nullable */);
63604
- if (!(nullStrippedTarget.flags & (1048576 /* Union */ | 131072 /* Never */))) {
63605
- target = getNormalizedType(nullStrippedTarget, /*writing*/ true);
63606
- }
63607
- if (source === nullStrippedTarget)
63608
- return -1 /* True */;
63653
+ // See if we're relating a definitely non-nullable type to a union that includes null and/or undefined
63654
+ // plus a single non-nullable type. If so, remove null and/or undefined from the target type.
63655
+ if (source.flags & 470302716 /* DefinitelyNonNullable */ && target.flags & 1048576 /* Union */) {
63656
+ var types = target.types;
63657
+ var candidate = types.length === 2 && types[0].flags & 98304 /* Nullable */ ? types[1] :
63658
+ types.length === 3 && types[0].flags & 98304 /* Nullable */ && types[1].flags & 98304 /* Nullable */ ? types[2] :
63659
+ undefined;
63660
+ if (candidate && !(candidate.flags & 98304 /* Nullable */)) {
63661
+ target = getNormalizedType(candidate, /*writing*/ true);
63662
+ if (source === target)
63663
+ return -1 /* True */;
63664
+ }
63609
63665
  }
63610
63666
  if (relation === comparableRelation && !(target.flags & 131072 /* Never */) && isSimpleTypeRelatedTo(target, source, relation) ||
63611
63667
  isSimpleTypeRelatedTo(source, target, relation, reportErrors ? reportError : undefined))
63612
63668
  return -1 /* True */;
63613
- var isComparingJsxAttributes = !!(ts.getObjectFlags(source) & 2048 /* JsxAttributes */);
63614
- var isPerformingExcessPropertyChecks = !(intersectionState & 2 /* Target */) && (isObjectLiteralType(source) && ts.getObjectFlags(source) & 16384 /* FreshLiteral */);
63615
- if (isPerformingExcessPropertyChecks) {
63616
- if (hasExcessProperties(source, target, reportErrors)) {
63669
+ if (source.flags & 469499904 /* StructuredOrInstantiable */ || target.flags & 469499904 /* StructuredOrInstantiable */) {
63670
+ var isPerformingExcessPropertyChecks = !(intersectionState & 2 /* Target */) && (isObjectLiteralType(source) && ts.getObjectFlags(source) & 16384 /* FreshLiteral */);
63671
+ if (isPerformingExcessPropertyChecks) {
63672
+ if (hasExcessProperties(source, target, reportErrors)) {
63673
+ if (reportErrors) {
63674
+ reportRelationError(headMessage, source, originalTarget.aliasSymbol ? originalTarget : target);
63675
+ }
63676
+ return 0 /* False */;
63677
+ }
63678
+ }
63679
+ var isPerformingCommonPropertyChecks = relation !== comparableRelation && !(intersectionState & 2 /* Target */) &&
63680
+ source.flags & (131068 /* Primitive */ | 524288 /* Object */ | 2097152 /* Intersection */) && source !== globalObjectType &&
63681
+ target.flags & (524288 /* Object */ | 2097152 /* Intersection */) && isWeakType(target) &&
63682
+ (getPropertiesOfType(source).length > 0 || typeHasCallOrConstructSignatures(source));
63683
+ var isComparingJsxAttributes = !!(ts.getObjectFlags(source) & 2048 /* JsxAttributes */);
63684
+ if (isPerformingCommonPropertyChecks && !hasCommonProperties(source, target, isComparingJsxAttributes)) {
63617
63685
  if (reportErrors) {
63618
- reportRelationError(headMessage, source, originalTarget.aliasSymbol ? originalTarget : target);
63686
+ var sourceString = typeToString(originalSource.aliasSymbol ? originalSource : source);
63687
+ var targetString = typeToString(originalTarget.aliasSymbol ? originalTarget : target);
63688
+ var calls = getSignaturesOfType(source, 0 /* Call */);
63689
+ var constructs = getSignaturesOfType(source, 1 /* Construct */);
63690
+ if (calls.length > 0 && isRelatedTo(getReturnTypeOfSignature(calls[0]), target, 1 /* Source */, /*reportErrors*/ false) ||
63691
+ constructs.length > 0 && isRelatedTo(getReturnTypeOfSignature(constructs[0]), target, 1 /* Source */, /*reportErrors*/ false)) {
63692
+ reportError(ts.Diagnostics.Value_of_type_0_has_no_properties_in_common_with_type_1_Did_you_mean_to_call_it, sourceString, targetString);
63693
+ }
63694
+ else {
63695
+ reportError(ts.Diagnostics.Type_0_has_no_properties_in_common_with_type_1, sourceString, targetString);
63696
+ }
63619
63697
  }
63620
63698
  return 0 /* False */;
63621
63699
  }
63622
- }
63623
- var isPerformingCommonPropertyChecks = relation !== comparableRelation && !(intersectionState & 2 /* Target */) &&
63624
- source.flags & (131068 /* Primitive */ | 524288 /* Object */ | 2097152 /* Intersection */) && source !== globalObjectType &&
63625
- target.flags & (524288 /* Object */ | 2097152 /* Intersection */) && isWeakType(target) &&
63626
- (getPropertiesOfType(source).length > 0 || typeHasCallOrConstructSignatures(source));
63627
- if (isPerformingCommonPropertyChecks && !hasCommonProperties(source, target, isComparingJsxAttributes)) {
63628
- if (reportErrors) {
63629
- var sourceString = typeToString(originalSource.aliasSymbol ? originalSource : source);
63630
- var targetString = typeToString(originalTarget.aliasSymbol ? originalTarget : target);
63631
- var calls = getSignaturesOfType(source, 0 /* Call */);
63632
- var constructs = getSignaturesOfType(source, 1 /* Construct */);
63633
- if (calls.length > 0 && isRelatedTo(getReturnTypeOfSignature(calls[0]), target, 1 /* Source */, /*reportErrors*/ false) ||
63634
- constructs.length > 0 && isRelatedTo(getReturnTypeOfSignature(constructs[0]), target, 1 /* Source */, /*reportErrors*/ false)) {
63635
- reportError(ts.Diagnostics.Value_of_type_0_has_no_properties_in_common_with_type_1_Did_you_mean_to_call_it, sourceString, targetString);
63636
- }
63637
- else {
63638
- reportError(ts.Diagnostics.Type_0_has_no_properties_in_common_with_type_1, sourceString, targetString);
63639
- }
63700
+ traceUnionsOrIntersectionsTooLarge(source, target);
63701
+ var skipCaching = source.flags & 1048576 /* Union */ && source.types.length < 4 && !(target.flags & 1048576 /* Union */) ||
63702
+ target.flags & 1048576 /* Union */ && target.types.length < 4 && !(source.flags & 469499904 /* StructuredOrInstantiable */);
63703
+ var result_7 = skipCaching ?
63704
+ unionOrIntersectionRelatedTo(source, target, reportErrors, intersectionState) :
63705
+ recursiveTypeRelatedTo(source, target, reportErrors, intersectionState, recursionFlags);
63706
+ // For certain combinations involving intersections and optional, excess, or mismatched properties we need
63707
+ // an extra property check where the intersection is viewed as a single object. The following are motivating
63708
+ // examples that all should be errors, but aren't without this extra property check:
63709
+ //
63710
+ // let obj: { a: { x: string } } & { c: number } = { a: { x: 'hello', y: 2 }, c: 5 }; // Nested excess property
63711
+ //
63712
+ // declare let wrong: { a: { y: string } };
63713
+ // let weak: { a?: { x?: number } } & { c?: string } = wrong; // Nested weak object type
63714
+ //
63715
+ // function foo<T extends object>(x: { a?: string }, y: T & { a: boolean }) {
63716
+ // x = y; // Mismatched property in source intersection
63717
+ // }
63718
+ //
63719
+ // We suppress recursive intersection property checks because they can generate lots of work when relating
63720
+ // recursive intersections that are structurally similar but not exactly identical. See #37854.
63721
+ if (result_7 && !inPropertyCheck && (target.flags & 2097152 /* Intersection */ && (isPerformingExcessPropertyChecks || isPerformingCommonPropertyChecks) ||
63722
+ isNonGenericObjectType(target) && !isArrayType(target) && !isTupleType(target) && source.flags & 2097152 /* Intersection */ && getApparentType(source).flags & 3670016 /* StructuredType */ && !ts.some(source.types, function (t) { return !!(ts.getObjectFlags(t) & 524288 /* NonInferrableType */); }))) {
63723
+ inPropertyCheck = true;
63724
+ result_7 &= recursiveTypeRelatedTo(source, target, reportErrors, 4 /* PropertyCheck */, recursionFlags);
63725
+ inPropertyCheck = false;
63726
+ }
63727
+ if (result_7) {
63728
+ return result_7;
63640
63729
  }
63641
- return 0 /* False */;
63642
- }
63643
- traceUnionsOrIntersectionsTooLarge(source, target);
63644
- var result = 0 /* False */;
63645
- var saveErrorInfo = captureErrorCalculationState();
63646
- if ((source.flags & 1048576 /* Union */ || target.flags & 1048576 /* Union */) && getConstituentCount(source) * getConstituentCount(target) < 4) {
63647
- // We skip caching when source or target is a union with no more than three constituents.
63648
- result = structuredTypeRelatedTo(source, target, reportErrors, intersectionState | 8 /* UnionIntersectionCheck */);
63649
63730
  }
63650
- else if (source.flags & 3145728 /* UnionOrIntersection */ || target.flags & 3145728 /* UnionOrIntersection */) {
63651
- result = recursiveTypeRelatedTo(source, target, reportErrors, intersectionState | 8 /* UnionIntersectionCheck */, recursionFlags);
63731
+ if (reportErrors) {
63732
+ reportErrorResults(originalSource, originalTarget, source, target, headMessage);
63652
63733
  }
63653
- if (!result && !(source.flags & 1048576 /* Union */) && (source.flags & (469499904 /* StructuredOrInstantiable */) || target.flags & 469499904 /* StructuredOrInstantiable */)) {
63654
- if (result = recursiveTypeRelatedTo(source, target, reportErrors, intersectionState, recursionFlags)) {
63655
- resetErrorInfo(saveErrorInfo);
63734
+ return 0 /* False */;
63735
+ }
63736
+ function reportErrorResults(originalSource, originalTarget, source, target, headMessage) {
63737
+ var sourceHasBase = !!getSingleBaseForNonAugmentingSubtype(originalSource);
63738
+ var targetHasBase = !!getSingleBaseForNonAugmentingSubtype(originalTarget);
63739
+ source = (originalSource.aliasSymbol || sourceHasBase) ? originalSource : source;
63740
+ target = (originalTarget.aliasSymbol || targetHasBase) ? originalTarget : target;
63741
+ var maybeSuppress = overrideNextErrorInfo > 0;
63742
+ if (maybeSuppress) {
63743
+ overrideNextErrorInfo--;
63744
+ }
63745
+ if (source.flags & 524288 /* Object */ && target.flags & 524288 /* Object */) {
63746
+ var currentError = errorInfo;
63747
+ tryElaborateArrayLikeErrors(source, target, /*reportErrors*/ true);
63748
+ if (errorInfo !== currentError) {
63749
+ maybeSuppress = !!errorInfo;
63750
+ }
63751
+ }
63752
+ if (source.flags & 524288 /* Object */ && target.flags & 131068 /* Primitive */) {
63753
+ tryElaborateErrorsForPrimitivesAndObjects(source, target);
63754
+ }
63755
+ else if (source.symbol && source.flags & 524288 /* Object */ && globalObjectType === source) {
63756
+ reportError(ts.Diagnostics.The_Object_type_is_assignable_to_very_few_other_types_Did_you_mean_to_use_the_any_type_instead);
63757
+ }
63758
+ else if (ts.getObjectFlags(source) & 2048 /* JsxAttributes */ && target.flags & 2097152 /* Intersection */) {
63759
+ var targetTypes = target.types;
63760
+ var intrinsicAttributes = getJsxType(JsxNames.IntrinsicAttributes, errorNode);
63761
+ var intrinsicClassAttributes = getJsxType(JsxNames.IntrinsicClassAttributes, errorNode);
63762
+ if (!isErrorType(intrinsicAttributes) && !isErrorType(intrinsicClassAttributes) &&
63763
+ (ts.contains(targetTypes, intrinsicAttributes) || ts.contains(targetTypes, intrinsicClassAttributes))) {
63764
+ // do not report top error
63765
+ return;
63656
63766
  }
63657
63767
  }
63658
- if (!result && source.flags & (2097152 /* Intersection */ | 262144 /* TypeParameter */)) {
63659
- // The combined constraint of an intersection type is the intersection of the constraints of
63660
- // the constituents. When an intersection type contains instantiable types with union type
63661
- // constraints, there are situations where we need to examine the combined constraint. One is
63662
- // when the target is a union type. Another is when the intersection contains types belonging
63663
- // to one of the disjoint domains. For example, given type variables T and U, each with the
63664
- // constraint 'string | number', the combined constraint of 'T & U' is 'string | number' and
63665
- // we need to check this constraint against a union on the target side. Also, given a type
63666
- // variable V constrained to 'string | number', 'V & number' has a combined constraint of
63667
- // 'string & number | number & number' which reduces to just 'number'.
63668
- // This also handles type parameters, as a type parameter with a union constraint compared against a union
63669
- // needs to have its constraint hoisted into an intersection with said type parameter, this way
63670
- // the type param can be compared with itself in the target (with the influence of its constraint to match other parts)
63671
- // For example, if `T extends 1 | 2` and `U extends 2 | 3` and we compare `T & U` to `T & U & (1 | 2 | 3)`
63672
- var constraint = getEffectiveConstraintOfIntersection(source.flags & 2097152 /* Intersection */ ? source.types : [source], !!(target.flags & 1048576 /* Union */));
63673
- if (constraint && (source.flags & 2097152 /* Intersection */ || target.flags & 1048576 /* Union */)) {
63674
- if (everyType(constraint, function (c) { return c !== source; })) { // Skip comparison if expansion contains the source itself
63675
- // TODO: Stack errors so we get a pyramid for the "normal" comparison above, _and_ a second for this
63676
- if (result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
63677
- resetErrorInfo(saveErrorInfo);
63678
- }
63679
- }
63680
- }
63768
+ else {
63769
+ errorInfo = elaborateNeverIntersection(errorInfo, originalTarget);
63681
63770
  }
63682
- // For certain combinations involving intersections and optional, excess, or mismatched properties we need
63683
- // an extra property check where the intersection is viewed as a single object. The following are motivating
63684
- // examples that all should be errors, but aren't without this extra property check:
63685
- //
63686
- // let obj: { a: { x: string } } & { c: number } = { a: { x: 'hello', y: 2 }, c: 5 }; // Nested excess property
63687
- //
63688
- // declare let wrong: { a: { y: string } };
63689
- // let weak: { a?: { x?: number } } & { c?: string } = wrong; // Nested weak object type
63690
- //
63691
- // function foo<T extends object>(x: { a?: string }, y: T & { a: boolean }) {
63692
- // x = y; // Mismatched property in source intersection
63693
- // }
63694
- //
63695
- // We suppress recursive intersection property checks because they can generate lots of work when relating
63696
- // recursive intersections that are structurally similar but not exactly identical. See #37854.
63697
- if (result && !inPropertyCheck && (target.flags & 2097152 /* Intersection */ && (isPerformingExcessPropertyChecks || isPerformingCommonPropertyChecks) ||
63698
- isNonGenericObjectType(target) && !isArrayType(target) && !isTupleType(target) && source.flags & 2097152 /* Intersection */ && getApparentType(source).flags & 3670016 /* StructuredType */ && !ts.some(source.types, function (t) { return !!(ts.getObjectFlags(t) & 524288 /* NonInferrableType */); }))) {
63699
- inPropertyCheck = true;
63700
- result &= recursiveTypeRelatedTo(source, target, reportErrors, 4 /* PropertyCheck */, recursionFlags);
63701
- inPropertyCheck = false;
63702
- }
63703
- reportErrorResults(source, target, result, isComparingJsxAttributes);
63704
- return result;
63705
- function reportErrorResults(source, target, result, isComparingJsxAttributes) {
63706
- if (!result && reportErrors) {
63707
- var sourceHasBase = !!getSingleBaseForNonAugmentingSubtype(originalSource);
63708
- var targetHasBase = !!getSingleBaseForNonAugmentingSubtype(originalTarget);
63709
- source = (originalSource.aliasSymbol || sourceHasBase) ? originalSource : source;
63710
- target = (originalTarget.aliasSymbol || targetHasBase) ? originalTarget : target;
63711
- var maybeSuppress = overrideNextErrorInfo > 0;
63712
- if (maybeSuppress) {
63713
- overrideNextErrorInfo--;
63714
- }
63715
- if (source.flags & 524288 /* Object */ && target.flags & 524288 /* Object */) {
63716
- var currentError = errorInfo;
63717
- tryElaborateArrayLikeErrors(source, target, reportErrors);
63718
- if (errorInfo !== currentError) {
63719
- maybeSuppress = !!errorInfo;
63720
- }
63721
- }
63722
- if (source.flags & 524288 /* Object */ && target.flags & 131068 /* Primitive */) {
63723
- tryElaborateErrorsForPrimitivesAndObjects(source, target);
63724
- }
63725
- else if (source.symbol && source.flags & 524288 /* Object */ && globalObjectType === source) {
63726
- reportError(ts.Diagnostics.The_Object_type_is_assignable_to_very_few_other_types_Did_you_mean_to_use_the_any_type_instead);
63727
- }
63728
- else if (isComparingJsxAttributes && target.flags & 2097152 /* Intersection */) {
63729
- var targetTypes = target.types;
63730
- var intrinsicAttributes = getJsxType(JsxNames.IntrinsicAttributes, errorNode);
63731
- var intrinsicClassAttributes = getJsxType(JsxNames.IntrinsicClassAttributes, errorNode);
63732
- if (!isErrorType(intrinsicAttributes) && !isErrorType(intrinsicClassAttributes) &&
63733
- (ts.contains(targetTypes, intrinsicAttributes) || ts.contains(targetTypes, intrinsicClassAttributes))) {
63734
- // do not report top error
63735
- return result;
63736
- }
63737
- }
63738
- else {
63739
- errorInfo = elaborateNeverIntersection(errorInfo, originalTarget);
63740
- }
63741
- if (!headMessage && maybeSuppress) {
63742
- lastSkippedInfo = [source, target];
63743
- // Used by, eg, missing property checking to replace the top-level message with a more informative one
63744
- return result;
63745
- }
63746
- reportRelationError(headMessage, source, target);
63747
- }
63771
+ if (!headMessage && maybeSuppress) {
63772
+ lastSkippedInfo = [source, target];
63773
+ // Used by, eg, missing property checking to replace the top-level message with a more informative one
63774
+ return;
63748
63775
  }
63776
+ reportRelationError(headMessage, source, target);
63749
63777
  }
63750
63778
  function traceUnionsOrIntersectionsTooLarge(source, target) {
63751
63779
  if (!ts.tracing) {
@@ -63772,21 +63800,6 @@ var ts;
63772
63800
  }
63773
63801
  }
63774
63802
  }
63775
- function isIdenticalTo(source, target, recursionFlags) {
63776
- if (source.flags !== target.flags)
63777
- return 0 /* False */;
63778
- if (source.flags & 67358815 /* Singleton */)
63779
- return -1 /* True */;
63780
- traceUnionsOrIntersectionsTooLarge(source, target);
63781
- if (source.flags & 3145728 /* UnionOrIntersection */) {
63782
- var result_7 = eachTypeRelatedToSomeType(source, target);
63783
- if (result_7) {
63784
- result_7 &= eachTypeRelatedToSomeType(target, source);
63785
- }
63786
- return result_7;
63787
- }
63788
- return recursiveTypeRelatedTo(source, target, /*reportErrors*/ false, 0 /* None */, recursionFlags);
63789
- }
63790
63803
  function getTypeOfPropertyInTypes(types, name) {
63791
63804
  var appendPropType = function (propTypes, type) {
63792
63805
  var _a;
@@ -63885,6 +63898,41 @@ var ts;
63885
63898
  function shouldCheckAsExcessProperty(prop, container) {
63886
63899
  return prop.valueDeclaration && container.valueDeclaration && prop.valueDeclaration.parent === container.valueDeclaration;
63887
63900
  }
63901
+ function unionOrIntersectionRelatedTo(source, target, reportErrors, intersectionState) {
63902
+ // Note that these checks are specifically ordered to produce correct results. In particular,
63903
+ // we need to deconstruct unions before intersections (because unions are always at the top),
63904
+ // and we need to handle "each" relations before "some" relations for the same kind of type.
63905
+ if (source.flags & 1048576 /* Union */) {
63906
+ return relation === comparableRelation ?
63907
+ someTypeRelatedToType(source, target, reportErrors && !(source.flags & 131068 /* Primitive */), intersectionState) :
63908
+ eachTypeRelatedToType(source, target, reportErrors && !(source.flags & 131068 /* Primitive */), intersectionState);
63909
+ }
63910
+ if (target.flags & 1048576 /* Union */) {
63911
+ return typeRelatedToSomeType(getRegularTypeOfObjectLiteral(source), target, reportErrors && !(source.flags & 131068 /* Primitive */) && !(target.flags & 131068 /* Primitive */));
63912
+ }
63913
+ if (target.flags & 2097152 /* Intersection */) {
63914
+ return typeRelatedToEachType(getRegularTypeOfObjectLiteral(source), target, reportErrors, 2 /* Target */);
63915
+ }
63916
+ // Source is an intersection. For the comparable relation, if the target is a primitive type we hoist the
63917
+ // constraints of all non-primitive types in the source into a new intersection. We do this because the
63918
+ // intersection may further constrain the constraints of the non-primitive types. For example, given a type
63919
+ // parameter 'T extends 1 | 2', the intersection 'T & 1' should be reduced to '1' such that it doesn't
63920
+ // appear to be comparable to '2'.
63921
+ if (relation === comparableRelation && target.flags & 131068 /* Primitive */) {
63922
+ var constraints = ts.sameMap(source.types, getBaseConstraintOrType);
63923
+ if (constraints !== source.types) {
63924
+ source = getIntersectionType(constraints);
63925
+ if (!(source.flags & 2097152 /* Intersection */)) {
63926
+ return isRelatedTo(source, target, 1 /* Source */, /*reportErrors*/ false);
63927
+ }
63928
+ }
63929
+ }
63930
+ // Check to see if any constituents of the intersection are immediately related to the target.
63931
+ // Don't report errors though. Elaborating on whether a source constituent is related to the target is
63932
+ // not actually useful and leads to some confusing error messages. Instead, we rely on the caller
63933
+ // checking whether the full intersection viewed as an object is related to the target.
63934
+ return someTypeRelatedToType(source, target, /*reportErrors*/ false, 1 /* Source */);
63935
+ }
63888
63936
  function eachTypeRelatedToSomeType(source, target) {
63889
63937
  var result = -1 /* True */;
63890
63938
  var sourceTypes = source.types;
@@ -63920,8 +63968,11 @@ var ts;
63920
63968
  }
63921
63969
  }
63922
63970
  if (reportErrors) {
63971
+ // Elaborate only if we can find a best matching type in the target union
63923
63972
  var bestMatchingType = getBestMatchingType(source, target, isRelatedTo);
63924
- isRelatedTo(source, bestMatchingType || targetTypes[targetTypes.length - 1], 2 /* Target */, /*reportErrors*/ true);
63973
+ if (bestMatchingType) {
63974
+ isRelatedTo(source, bestMatchingType, 2 /* Target */, /*reportErrors*/ true);
63975
+ }
63925
63976
  }
63926
63977
  return 0 /* False */;
63927
63978
  }
@@ -64057,7 +64108,7 @@ var ts;
64057
64108
  if (overflow) {
64058
64109
  return 0 /* False */;
64059
64110
  }
64060
- var keyIntersectionState = intersectionState | (inPropertyCheck ? 16 /* InPropertyCheck */ : 0);
64111
+ var keyIntersectionState = intersectionState | (inPropertyCheck ? 8 /* InPropertyCheck */ : 0);
64061
64112
  var id = getRelationKey(source, target, keyIntersectionState, relation, /*ingnoreConstraints*/ false);
64062
64113
  var entry = relation.get(id);
64063
64114
  if (entry !== undefined) {
@@ -64125,6 +64176,7 @@ var ts;
64125
64176
  return originalHandler(onlyUnreliable);
64126
64177
  };
64127
64178
  }
64179
+ var result;
64128
64180
  if (expandingFlags === 3 /* Both */) {
64129
64181
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.instant("checkTypes" /* CheckTypes */, "recursiveTypeRelatedTo_DepthLimit", {
64130
64182
  sourceId: source.id,
@@ -64134,8 +64186,13 @@ var ts;
64134
64186
  depth: sourceDepth,
64135
64187
  targetDepth: targetDepth
64136
64188
  });
64189
+ result = 3 /* Maybe */;
64190
+ }
64191
+ else {
64192
+ ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("checkTypes" /* CheckTypes */, "structuredTypeRelatedTo", { sourceId: source.id, targetId: target.id });
64193
+ result = structuredTypeRelatedTo(source, target, reportErrors, intersectionState);
64194
+ ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
64137
64195
  }
64138
- var result = expandingFlags !== 3 /* Both */ ? structuredTypeRelatedTo(source, target, reportErrors, intersectionState) : 3 /* Maybe */;
64139
64196
  if (outofbandVarianceMarkerHandler) {
64140
64197
  outofbandVarianceMarkerHandler = originalHandler;
64141
64198
  }
@@ -64167,98 +64224,97 @@ var ts;
64167
64224
  return result;
64168
64225
  }
64169
64226
  function structuredTypeRelatedTo(source, target, reportErrors, intersectionState) {
64170
- ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("checkTypes" /* CheckTypes */, "structuredTypeRelatedTo", { sourceId: source.id, targetId: target.id });
64171
- var result = structuredTypeRelatedToWorker(source, target, reportErrors, intersectionState);
64172
- ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
64173
- return result;
64174
- }
64175
- function structuredTypeRelatedToWorker(source, target, reportErrors, intersectionState) {
64176
64227
  if (intersectionState & 4 /* PropertyCheck */) {
64177
64228
  return propertiesRelatedTo(source, target, reportErrors, /*excludedProperties*/ undefined, 0 /* None */);
64178
64229
  }
64179
- if (intersectionState & 8 /* UnionIntersectionCheck */) {
64180
- // Note that these checks are specifically ordered to produce correct results. In particular,
64181
- // we need to deconstruct unions before intersections (because unions are always at the top),
64182
- // and we need to handle "each" relations before "some" relations for the same kind of type.
64183
- if (source.flags & 1048576 /* Union */) {
64184
- return relation === comparableRelation ?
64185
- someTypeRelatedToType(source, target, reportErrors && !(source.flags & 131068 /* Primitive */), intersectionState & ~8 /* UnionIntersectionCheck */) :
64186
- eachTypeRelatedToType(source, target, reportErrors && !(source.flags & 131068 /* Primitive */), intersectionState & ~8 /* UnionIntersectionCheck */);
64187
- }
64188
- if (target.flags & 1048576 /* Union */) {
64189
- return typeRelatedToSomeType(getRegularTypeOfObjectLiteral(source), target, reportErrors && !(source.flags & 131068 /* Primitive */) && !(target.flags & 131068 /* Primitive */));
64190
- }
64191
- if (target.flags & 2097152 /* Intersection */) {
64192
- return typeRelatedToEachType(getRegularTypeOfObjectLiteral(source), target, reportErrors, 2 /* Target */);
64193
- }
64194
- // Source is an intersection. For the comparable relation, if the target is a primitive type we hoist the
64195
- // constraints of all non-primitive types in the source into a new intersection. We do this because the
64196
- // intersection may further constrain the constraints of the non-primitive types. For example, given a type
64197
- // parameter 'T extends 1 | 2', the intersection 'T & 1' should be reduced to '1' such that it doesn't
64198
- // appear to be comparable to '2'.
64199
- if (relation === comparableRelation && target.flags & 131068 /* Primitive */) {
64200
- var constraints = ts.sameMap(source.types, getBaseConstraintOrType);
64201
- if (constraints !== source.types) {
64202
- source = getIntersectionType(constraints);
64203
- if (!(source.flags & 2097152 /* Intersection */)) {
64204
- return isRelatedTo(source, target, 1 /* Source */, /*reportErrors*/ false);
64205
- }
64230
+ var result;
64231
+ var originalErrorInfo;
64232
+ var varianceCheckFailed = false;
64233
+ var saveErrorInfo = captureErrorCalculationState();
64234
+ var sourceFlags = source.flags;
64235
+ var targetFlags = target.flags;
64236
+ if (relation === identityRelation) {
64237
+ // We've already checked that source.flags and target.flags are identical
64238
+ if (sourceFlags & 3145728 /* UnionOrIntersection */) {
64239
+ var result_8 = eachTypeRelatedToSomeType(source, target);
64240
+ if (result_8) {
64241
+ result_8 &= eachTypeRelatedToSomeType(target, source);
64206
64242
  }
64243
+ return result_8;
64207
64244
  }
64208
- // Check to see if any constituents of the intersection are immediately related to the target.
64209
- //
64210
- // Don't report errors though. Checking whether a constituent is related to the source is not actually
64211
- // useful and leads to some confusing error messages. Instead it is better to let the below checks
64212
- // take care of this, or to not elaborate at all. For instance,
64213
- //
64214
- // - For an object type (such as 'C = A & B'), users are usually more interested in structural errors.
64215
- //
64216
- // - For a union type (such as '(A | B) = (C & D)'), it's better to hold onto the whole intersection
64217
- // than to report that 'D' is not assignable to 'A' or 'B'.
64218
- //
64219
- // - For a primitive type or type parameter (such as 'number = A & B') there is no point in
64220
- // breaking the intersection apart.
64221
- return someTypeRelatedToType(source, target, /*reportErrors*/ false, 1 /* Source */);
64222
- }
64223
- var flags = source.flags & target.flags;
64224
- if (relation === identityRelation && !(flags & 524288 /* Object */)) {
64225
- if (flags & 4194304 /* Index */) {
64245
+ if (sourceFlags & 4194304 /* Index */) {
64226
64246
  return isRelatedTo(source.type, target.type, 3 /* Both */, /*reportErrors*/ false);
64227
64247
  }
64228
- var result_8 = 0 /* False */;
64229
- if (flags & 8388608 /* IndexedAccess */) {
64230
- if (result_8 = isRelatedTo(source.objectType, target.objectType, 3 /* Both */, /*reportErrors*/ false)) {
64231
- if (result_8 &= isRelatedTo(source.indexType, target.indexType, 3 /* Both */, /*reportErrors*/ false)) {
64232
- return result_8;
64248
+ if (sourceFlags & 8388608 /* IndexedAccess */) {
64249
+ if (result = isRelatedTo(source.objectType, target.objectType, 3 /* Both */, /*reportErrors*/ false)) {
64250
+ if (result &= isRelatedTo(source.indexType, target.indexType, 3 /* Both */, /*reportErrors*/ false)) {
64251
+ return result;
64233
64252
  }
64234
64253
  }
64235
64254
  }
64236
- if (flags & 16777216 /* Conditional */) {
64255
+ if (sourceFlags & 16777216 /* Conditional */) {
64237
64256
  if (source.root.isDistributive === target.root.isDistributive) {
64238
- if (result_8 = isRelatedTo(source.checkType, target.checkType, 3 /* Both */, /*reportErrors*/ false)) {
64239
- if (result_8 &= isRelatedTo(source.extendsType, target.extendsType, 3 /* Both */, /*reportErrors*/ false)) {
64240
- if (result_8 &= isRelatedTo(getTrueTypeFromConditionalType(source), getTrueTypeFromConditionalType(target), 3 /* Both */, /*reportErrors*/ false)) {
64241
- if (result_8 &= isRelatedTo(getFalseTypeFromConditionalType(source), getFalseTypeFromConditionalType(target), 3 /* Both */, /*reportErrors*/ false)) {
64242
- return result_8;
64257
+ if (result = isRelatedTo(source.checkType, target.checkType, 3 /* Both */, /*reportErrors*/ false)) {
64258
+ if (result &= isRelatedTo(source.extendsType, target.extendsType, 3 /* Both */, /*reportErrors*/ false)) {
64259
+ if (result &= isRelatedTo(getTrueTypeFromConditionalType(source), getTrueTypeFromConditionalType(target), 3 /* Both */, /*reportErrors*/ false)) {
64260
+ if (result &= isRelatedTo(getFalseTypeFromConditionalType(source), getFalseTypeFromConditionalType(target), 3 /* Both */, /*reportErrors*/ false)) {
64261
+ return result;
64243
64262
  }
64244
64263
  }
64245
64264
  }
64246
64265
  }
64247
64266
  }
64248
64267
  }
64249
- if (flags & 33554432 /* Substitution */) {
64268
+ if (sourceFlags & 33554432 /* Substitution */) {
64250
64269
  return isRelatedTo(source.substitute, target.substitute, 3 /* Both */, /*reportErrors*/ false);
64251
64270
  }
64252
- return 0 /* False */;
64271
+ if (!(sourceFlags & 524288 /* Object */)) {
64272
+ return 0 /* False */;
64273
+ }
64274
+ }
64275
+ else if (sourceFlags & 3145728 /* UnionOrIntersection */ || targetFlags & 3145728 /* UnionOrIntersection */) {
64276
+ if (result = unionOrIntersectionRelatedTo(source, target, reportErrors, intersectionState)) {
64277
+ return result;
64278
+ }
64279
+ if (source.flags & 2097152 /* Intersection */ || source.flags & 262144 /* TypeParameter */ && target.flags & 1048576 /* Union */) {
64280
+ // The combined constraint of an intersection type is the intersection of the constraints of
64281
+ // the constituents. When an intersection type contains instantiable types with union type
64282
+ // constraints, there are situations where we need to examine the combined constraint. One is
64283
+ // when the target is a union type. Another is when the intersection contains types belonging
64284
+ // to one of the disjoint domains. For example, given type variables T and U, each with the
64285
+ // constraint 'string | number', the combined constraint of 'T & U' is 'string | number' and
64286
+ // we need to check this constraint against a union on the target side. Also, given a type
64287
+ // variable V constrained to 'string | number', 'V & number' has a combined constraint of
64288
+ // 'string & number | number & number' which reduces to just 'number'.
64289
+ // This also handles type parameters, as a type parameter with a union constraint compared against a union
64290
+ // needs to have its constraint hoisted into an intersection with said type parameter, this way
64291
+ // the type param can be compared with itself in the target (with the influence of its constraint to match other parts)
64292
+ // For example, if `T extends 1 | 2` and `U extends 2 | 3` and we compare `T & U` to `T & U & (1 | 2 | 3)`
64293
+ var constraint = getEffectiveConstraintOfIntersection(source.flags & 2097152 /* Intersection */ ? source.types : [source], !!(target.flags & 1048576 /* Union */));
64294
+ if (constraint && everyType(constraint, function (c) { return c !== source; })) { // Skip comparison if expansion contains the source itself
64295
+ // TODO: Stack errors so we get a pyramid for the "normal" comparison above, _and_ a second for this
64296
+ if (result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
64297
+ resetErrorInfo(saveErrorInfo);
64298
+ return result;
64299
+ }
64300
+ }
64301
+ }
64302
+ // The ordered decomposition above doesn't handle all cases. Specifically, we also need to handle:
64303
+ // Source is instantiable (e.g. source has union or intersection constraint).
64304
+ // Source is an object, target is a union (e.g. { a, b: boolean } <=> { a, b: true } | { a, b: false }).
64305
+ // Source is an intersection, target is an object (e.g. { a } & { b } <=> { a, b }).
64306
+ // Source is an intersection, target is a union (e.g. { a } & { b: boolean } <=> { a, b: true } | { a, b: false }).
64307
+ // Source is an intersection, target instantiable (e.g. string & { tag } <=> T["a"] constrained to string & { tag }).
64308
+ if (!(sourceFlags & 465829888 /* Instantiable */ ||
64309
+ sourceFlags & 524288 /* Object */ && targetFlags & 1048576 /* Union */ ||
64310
+ sourceFlags & 2097152 /* Intersection */ && targetFlags & (524288 /* Object */ | 1048576 /* Union */ | 465829888 /* Instantiable */))) {
64311
+ return 0 /* False */;
64312
+ }
64253
64313
  }
64254
- var result;
64255
- var originalErrorInfo;
64256
- var varianceCheckFailed = false;
64257
- var saveErrorInfo = captureErrorCalculationState();
64258
64314
  // We limit alias variance probing to only object and conditional types since their alias behavior
64259
64315
  // is more predictable than other, interned types, which may or may not have an alias depending on
64260
64316
  // the order in which things were checked.
64261
- if (source.flags & (524288 /* Object */ | 16777216 /* Conditional */) && source.aliasSymbol &&
64317
+ if (sourceFlags & (524288 /* Object */ | 16777216 /* Conditional */) && source.aliasSymbol &&
64262
64318
  source.aliasTypeArguments && source.aliasSymbol === target.aliasSymbol &&
64263
64319
  !(source.aliasTypeArgumentsContainsMarker || target.aliasTypeArgumentsContainsMarker)) {
64264
64320
  var variances = getAliasVariances(source.aliasSymbol);
@@ -64276,7 +64332,7 @@ var ts;
64276
64332
  isSingleElementGenericTupleType(target) && (target.target.readonly || isMutableArrayOrTuple(getBaseConstraintOfType(source) || source)) && (result = isRelatedTo(source, getTypeArguments(target)[0], 2 /* Target */))) {
64277
64333
  return result;
64278
64334
  }
64279
- if (target.flags & 262144 /* TypeParameter */) {
64335
+ if (targetFlags & 262144 /* TypeParameter */) {
64280
64336
  // A source type { [P in Q]: X } is related to a target type T if keyof T is related to Q and X is related to T[Q].
64281
64337
  if (ts.getObjectFlags(source) & 32 /* Mapped */ && !source.declaration.nameType && isRelatedTo(getIndexType(target), getConstraintTypeFromMappedType(source), 3 /* Both */)) {
64282
64338
  if (!(getMappedTypeModifiers(source) & 4 /* IncludeOptional */)) {
@@ -64288,10 +64344,10 @@ var ts;
64288
64344
  }
64289
64345
  }
64290
64346
  }
64291
- else if (target.flags & 4194304 /* Index */) {
64347
+ else if (targetFlags & 4194304 /* Index */) {
64292
64348
  var targetType_1 = target.type;
64293
64349
  // A keyof S is related to a keyof T if T is related to S.
64294
- if (source.flags & 4194304 /* Index */) {
64350
+ if (sourceFlags & 4194304 /* Index */) {
64295
64351
  if (result = isRelatedTo(targetType_1, source.type, 3 /* Both */, /*reportErrors*/ false)) {
64296
64352
  return result;
64297
64353
  }
@@ -64342,8 +64398,8 @@ var ts;
64342
64398
  }
64343
64399
  }
64344
64400
  }
64345
- else if (target.flags & 8388608 /* IndexedAccess */) {
64346
- if (source.flags & 8388608 /* IndexedAccess */) {
64401
+ else if (targetFlags & 8388608 /* IndexedAccess */) {
64402
+ if (sourceFlags & 8388608 /* IndexedAccess */) {
64347
64403
  // Relate components directly before falling back to constraint relationships
64348
64404
  // A type S[K] is related to a type T[J] if S is related to T and K is related to J.
64349
64405
  if (result = isRelatedTo(source.objectType, target.objectType, 3 /* Both */, reportErrors)) {
@@ -64449,7 +64505,7 @@ var ts;
64449
64505
  }
64450
64506
  }
64451
64507
  }
64452
- else if (target.flags & 16777216 /* Conditional */) {
64508
+ else if (targetFlags & 16777216 /* Conditional */) {
64453
64509
  // If we reach 10 levels of nesting for the same conditional type, assume it is an infinitely expanding recursive
64454
64510
  // conditional type and bail out with a Ternary.Maybe result.
64455
64511
  if (isDeeplyNestedType(target, targetStack, targetDepth, 10)) {
@@ -64474,8 +64530,8 @@ var ts;
64474
64530
  }
64475
64531
  }
64476
64532
  }
64477
- else if (target.flags & 134217728 /* TemplateLiteral */) {
64478
- if (source.flags & 134217728 /* TemplateLiteral */) {
64533
+ else if (targetFlags & 134217728 /* TemplateLiteral */) {
64534
+ if (sourceFlags & 134217728 /* TemplateLiteral */) {
64479
64535
  if (relation === comparableRelation) {
64480
64536
  return templateLiteralTypesDefinitelyUnrelated(source, target) ? 0 /* False */ : -1 /* True */;
64481
64537
  }
@@ -64487,11 +64543,11 @@ var ts;
64487
64543
  return -1 /* True */;
64488
64544
  }
64489
64545
  }
64490
- if (source.flags & 8650752 /* TypeVariable */) {
64491
- // IndexedAccess comparisons are handled above in the `target.flags & TypeFlage.IndexedAccess` branch
64492
- if (!(source.flags & 8388608 /* IndexedAccess */ && target.flags & 8388608 /* IndexedAccess */)) {
64546
+ if (sourceFlags & 8650752 /* TypeVariable */) {
64547
+ // IndexedAccess comparisons are handled above in the `targetFlags & TypeFlage.IndexedAccess` branch
64548
+ if (!(sourceFlags & 8388608 /* IndexedAccess */ && targetFlags & 8388608 /* IndexedAccess */)) {
64493
64549
  var constraint = getConstraintOfType(source);
64494
- if (!constraint || (source.flags & 262144 /* TypeParameter */ && constraint.flags & 1 /* Any */)) {
64550
+ if (!constraint || (sourceFlags & 262144 /* TypeParameter */ && constraint.flags & 1 /* Any */)) {
64495
64551
  // A type variable with no constraint is not related to the non-primitive object type.
64496
64552
  if (result = isRelatedTo(emptyObjectType, extractTypesOfKind(target, ~67108864 /* NonPrimitive */), 3 /* Both */)) {
64497
64553
  resetErrorInfo(saveErrorInfo);
@@ -64504,7 +64560,7 @@ var ts;
64504
64560
  return result;
64505
64561
  }
64506
64562
  // slower, fuller, this-instantiated check (necessary when comparing raw `this` types from base classes), see `subclassWithPolymorphicThisIsAssignable.ts` test for example
64507
- else if (result = isRelatedTo(getTypeWithThisArgument(constraint, source), target, 1 /* Source */, reportErrors && !(target.flags & source.flags & 262144 /* TypeParameter */), /*headMessage*/ undefined, intersectionState)) {
64563
+ else if (result = isRelatedTo(getTypeWithThisArgument(constraint, source), target, 1 /* Source */, reportErrors && !(targetFlags & sourceFlags & 262144 /* TypeParameter */), /*headMessage*/ undefined, intersectionState)) {
64508
64564
  resetErrorInfo(saveErrorInfo);
64509
64565
  return result;
64510
64566
  }
@@ -64521,14 +64577,14 @@ var ts;
64521
64577
  }
64522
64578
  }
64523
64579
  }
64524
- else if (source.flags & 4194304 /* Index */) {
64580
+ else if (sourceFlags & 4194304 /* Index */) {
64525
64581
  if (result = isRelatedTo(keyofConstraintType, target, 1 /* Source */, reportErrors)) {
64526
64582
  resetErrorInfo(saveErrorInfo);
64527
64583
  return result;
64528
64584
  }
64529
64585
  }
64530
- else if (source.flags & 134217728 /* TemplateLiteral */ && !(target.flags & 524288 /* Object */)) {
64531
- if (!(target.flags & 134217728 /* TemplateLiteral */)) {
64586
+ else if (sourceFlags & 134217728 /* TemplateLiteral */ && !(targetFlags & 524288 /* Object */)) {
64587
+ if (!(targetFlags & 134217728 /* TemplateLiteral */)) {
64532
64588
  var constraint = getBaseConstraintOfType(source);
64533
64589
  if (constraint && constraint !== source && (result = isRelatedTo(constraint, target, 1 /* Source */, reportErrors))) {
64534
64590
  resetErrorInfo(saveErrorInfo);
@@ -64536,8 +64592,8 @@ var ts;
64536
64592
  }
64537
64593
  }
64538
64594
  }
64539
- else if (source.flags & 268435456 /* StringMapping */) {
64540
- if (target.flags & 268435456 /* StringMapping */ && source.symbol === target.symbol) {
64595
+ else if (sourceFlags & 268435456 /* StringMapping */) {
64596
+ if (targetFlags & 268435456 /* StringMapping */ && source.symbol === target.symbol) {
64541
64597
  if (result = isRelatedTo(source.type, target.type, 3 /* Both */, reportErrors)) {
64542
64598
  resetErrorInfo(saveErrorInfo);
64543
64599
  return result;
@@ -64551,14 +64607,14 @@ var ts;
64551
64607
  }
64552
64608
  }
64553
64609
  }
64554
- else if (source.flags & 16777216 /* Conditional */) {
64610
+ else if (sourceFlags & 16777216 /* Conditional */) {
64555
64611
  // If we reach 10 levels of nesting for the same conditional type, assume it is an infinitely expanding recursive
64556
64612
  // conditional type and bail out with a Ternary.Maybe result.
64557
64613
  if (isDeeplyNestedType(source, sourceStack, sourceDepth, 10)) {
64558
64614
  resetErrorInfo(saveErrorInfo);
64559
64615
  return 3 /* Maybe */;
64560
64616
  }
64561
- if (target.flags & 16777216 /* Conditional */) {
64617
+ if (targetFlags & 16777216 /* Conditional */) {
64562
64618
  // Two conditional types 'T1 extends U1 ? X1 : Y1' and 'T2 extends U2 ? X2 : Y2' are related if
64563
64619
  // one of T1 and T2 is related to the other, U1 and U2 are identical types, X1 is related to X2,
64564
64620
  // and Y1 is related to Y2.
@@ -64618,9 +64674,10 @@ var ts;
64618
64674
  }
64619
64675
  return 0 /* False */;
64620
64676
  }
64621
- var sourceIsPrimitive = !!(source.flags & 131068 /* Primitive */);
64677
+ var sourceIsPrimitive = !!(sourceFlags & 131068 /* Primitive */);
64622
64678
  if (relation !== identityRelation) {
64623
64679
  source = getApparentType(source);
64680
+ sourceFlags = source.flags;
64624
64681
  }
64625
64682
  else if (isGenericMappedType(source)) {
64626
64683
  return 0 /* False */;
@@ -64667,7 +64724,7 @@ var ts;
64667
64724
  // In a check of the form X = A & B, we will have previously checked if A relates to X or B relates
64668
64725
  // to X. Failing both of those we want to check if the aggregation of A and B's members structurally
64669
64726
  // relates to X. Thus, we include intersection types on the source side here.
64670
- if (source.flags & (524288 /* Object */ | 2097152 /* Intersection */) && target.flags & 524288 /* Object */) {
64727
+ if (sourceFlags & (524288 /* Object */ | 2097152 /* Intersection */) && targetFlags & 524288 /* Object */) {
64671
64728
  // Report structural errors only if we haven't reported any errors yet
64672
64729
  var reportStructuralErrors = reportErrors && errorInfo === saveErrorInfo.errorInfo && !sourceIsPrimitive;
64673
64730
  result = propertiesRelatedTo(source, target, reportStructuralErrors, /*excludedProperties*/ undefined, intersectionState);
@@ -64691,7 +64748,7 @@ var ts;
64691
64748
  // there exists a constituent of T for every combination of the discriminants of S
64692
64749
  // with respect to T. We do not report errors here, as we will use the existing
64693
64750
  // error result from checking each constituent of the union.
64694
- if (source.flags & (524288 /* Object */ | 2097152 /* Intersection */) && target.flags & 1048576 /* Union */) {
64751
+ if (sourceFlags & (524288 /* Object */ | 2097152 /* Intersection */) && targetFlags & 1048576 /* Union */) {
64695
64752
  var objectOnlyTarget = extractTypesOfKind(target, 524288 /* Object */ | 2097152 /* Intersection */ | 33554432 /* Substitution */);
64696
64753
  if (objectOnlyTarget.flags & 1048576 /* Union */) {
64697
64754
  var result_9 = typeRelatedToDiscriminatedType(source, objectOnlyTarget);
@@ -65215,7 +65272,6 @@ var ts;
65215
65272
  }
65216
65273
  }
65217
65274
  var result = -1 /* True */;
65218
- var saveErrorInfo = captureErrorCalculationState();
65219
65275
  var incompatibleReporter = kind === 1 /* Construct */ ? reportIncompatibleConstructSignatureReturn : reportIncompatibleCallSignatureReturn;
65220
65276
  var sourceObjectFlags = ts.getObjectFlags(source);
65221
65277
  var targetObjectFlags = ts.getObjectFlags(target);
@@ -65256,6 +65312,7 @@ var ts;
65256
65312
  else {
65257
65313
  outer: for (var _i = 0, targetSignatures_1 = targetSignatures; _i < targetSignatures_1.length; _i++) {
65258
65314
  var t = targetSignatures_1[_i];
65315
+ var saveErrorInfo = captureErrorCalculationState();
65259
65316
  // Only elaborate errors from the first failure
65260
65317
  var shouldElaborateErrors = reportErrors;
65261
65318
  for (var _c = 0, sourceSignatures_1 = sourceSignatures; _c < sourceSignatures_1.length; _c++) {
@@ -68426,9 +68483,6 @@ var ts;
68426
68483
  getUnionType(ts.map(type.types, mapper), 1 /* Literal */, aliasSymbol, aliasTypeArguments) :
68427
68484
  mapType(type, mapper);
68428
68485
  }
68429
- function getConstituentCount(type) {
68430
- return type.flags & 1048576 /* Union */ ? type.types.length : 1;
68431
- }
68432
68486
  function extractTypesOfKind(type, kind) {
68433
68487
  return filterType(type, function (t) { return (t.flags & kind) !== 0; });
68434
68488
  }
@@ -73149,6 +73203,9 @@ var ts;
73149
73203
  if (compilerOptions.noPropertyAccessFromIndexSignature && ts.isPropertyAccessExpression(node)) {
73150
73204
  error(right, ts.Diagnostics.Property_0_comes_from_an_index_signature_so_it_must_be_accessed_with_0, ts.unescapeLeadingUnderscores(right.escapedText));
73151
73205
  }
73206
+ if (indexInfo.declaration && ts.getCombinedNodeFlags(indexInfo.declaration) & 134217728 /* Deprecated */) {
73207
+ addDeprecatedSuggestion(right, [indexInfo.declaration], right.escapedText);
73208
+ }
73152
73209
  }
73153
73210
  else {
73154
73211
  if (isDeprecatedSymbol(prop) && isUncalledFunctionReference(node, prop) && prop.declarations) {
@@ -76094,21 +76151,22 @@ var ts;
76094
76151
  if (links.type === unknownType) {
76095
76152
  links.type = getTypeFromBindingPattern(declaration.name);
76096
76153
  }
76097
- assignBindingElementTypes(declaration.name);
76154
+ assignBindingElementTypes(declaration.name, links.type);
76098
76155
  }
76099
76156
  }
76100
76157
  }
76101
76158
  // When contextual typing assigns a type to a parameter that contains a binding pattern, we also need to push
76102
76159
  // the destructured type into the contained binding elements.
76103
- function assignBindingElementTypes(pattern) {
76160
+ function assignBindingElementTypes(pattern, parentType) {
76104
76161
  for (var _i = 0, _a = pattern.elements; _i < _a.length; _i++) {
76105
76162
  var element = _a[_i];
76106
76163
  if (!ts.isOmittedExpression(element)) {
76164
+ var type = getBindingElementTypeFromParentType(element, parentType);
76107
76165
  if (element.name.kind === 79 /* Identifier */) {
76108
- getSymbolLinks(getSymbolOfNode(element)).type = getTypeForBindingElement(element);
76166
+ getSymbolLinks(getSymbolOfNode(element)).type = type;
76109
76167
  }
76110
76168
  else {
76111
- assignBindingElementTypes(element.name);
76169
+ assignBindingElementTypes(element.name, type);
76112
76170
  }
76113
76171
  }
76114
76172
  }
@@ -79849,28 +79907,24 @@ var ts;
79849
79907
  if (returnType.flags & 1 /* Any */) {
79850
79908
  return;
79851
79909
  }
79910
+ var headMessage;
79852
79911
  var expectedReturnType;
79853
- var headMessage = getDiagnosticHeadMessageForDecoratorResolution(node);
79854
- var errorInfo;
79855
79912
  switch (node.parent.kind) {
79856
79913
  case 256 /* ClassDeclaration */:
79914
+ headMessage = ts.Diagnostics.Decorator_function_return_type_0_is_not_assignable_to_type_1;
79857
79915
  var classSymbol = getSymbolOfNode(node.parent);
79858
79916
  var classConstructorType = getTypeOfSymbol(classSymbol);
79859
79917
  expectedReturnType = getUnionType([classConstructorType, voidType]);
79860
79918
  break;
79861
- case 163 /* Parameter */:
79862
- expectedReturnType = voidType;
79863
- errorInfo = ts.chainDiagnosticMessages(
79864
- /*details*/ undefined, ts.Diagnostics.The_return_type_of_a_parameter_decorator_function_must_be_either_void_or_any);
79865
- break;
79866
79919
  case 166 /* PropertyDeclaration */:
79920
+ case 163 /* Parameter */:
79921
+ headMessage = ts.Diagnostics.Decorator_function_return_type_is_0_but_is_expected_to_be_void_or_any;
79867
79922
  expectedReturnType = voidType;
79868
- errorInfo = ts.chainDiagnosticMessages(
79869
- /*details*/ undefined, ts.Diagnostics.The_return_type_of_a_property_decorator_function_must_be_either_void_or_any);
79870
79923
  break;
79871
79924
  case 168 /* MethodDeclaration */:
79872
79925
  case 171 /* GetAccessor */:
79873
79926
  case 172 /* SetAccessor */:
79927
+ headMessage = ts.Diagnostics.Decorator_function_return_type_0_is_not_assignable_to_type_1;
79874
79928
  var methodType = getTypeOfNode(node.parent);
79875
79929
  var descriptorType = createTypedPropertyDescriptorType(methodType);
79876
79930
  expectedReturnType = getUnionType([descriptorType, voidType]);
@@ -79878,7 +79932,7 @@ var ts;
79878
79932
  default:
79879
79933
  return ts.Debug.fail();
79880
79934
  }
79881
- checkTypeAssignableTo(returnType, expectedReturnType, node, headMessage, function () { return errorInfo; });
79935
+ checkTypeAssignableTo(returnType, expectedReturnType, node, headMessage);
79882
79936
  }
79883
79937
  /**
79884
79938
  * If a TypeNode can be resolved to a value symbol imported from an external module, it is
@@ -85426,7 +85480,7 @@ var ts;
85426
85480
  if (resolvedTypeReferenceDirectives) {
85427
85481
  // populate reverse mapping: file path -> type reference directive that was resolved to this file
85428
85482
  fileToDirective = new ts.Map();
85429
- resolvedTypeReferenceDirectives.forEach(function (resolvedDirective, key) {
85483
+ resolvedTypeReferenceDirectives.forEach(function (resolvedDirective, key, mode) {
85430
85484
  if (!resolvedDirective || !resolvedDirective.resolvedFileName) {
85431
85485
  return;
85432
85486
  }
@@ -85434,7 +85488,7 @@ var ts;
85434
85488
  if (file) {
85435
85489
  // Add the transitive closure of path references loaded by this file (as long as they are not)
85436
85490
  // part of an existing type reference.
85437
- addReferencedFilesToTypeDirective(file, key);
85491
+ addReferencedFilesToTypeDirective(file, key, mode);
85438
85492
  }
85439
85493
  });
85440
85494
  }
@@ -85628,16 +85682,16 @@ var ts;
85628
85682
  }
85629
85683
  return false;
85630
85684
  }
85631
- function addReferencedFilesToTypeDirective(file, key) {
85685
+ function addReferencedFilesToTypeDirective(file, key, mode) {
85632
85686
  if (fileToDirective.has(file.path))
85633
85687
  return;
85634
- fileToDirective.set(file.path, key);
85688
+ fileToDirective.set(file.path, [key, mode]);
85635
85689
  for (var _i = 0, _a = file.referencedFiles; _i < _a.length; _i++) {
85636
- var fileName = _a[_i].fileName;
85690
+ var _b = _a[_i], fileName = _b.fileName, resolutionMode = _b.resolutionMode;
85637
85691
  var resolvedFile = ts.resolveTripleslashReference(fileName, file.fileName);
85638
85692
  var referencedFile = host.getSourceFile(resolvedFile);
85639
85693
  if (referencedFile) {
85640
- addReferencedFilesToTypeDirective(referencedFile, key);
85694
+ addReferencedFilesToTypeDirective(referencedFile, key, resolutionMode || file.impliedNodeFormat);
85641
85695
  }
85642
85696
  }
85643
85697
  }
@@ -87342,28 +87396,27 @@ var ts;
87342
87396
  }
87343
87397
  function findMostOverlappyType(source, unionTarget) {
87344
87398
  var bestMatch;
87345
- var matchingCount = 0;
87346
- for (var _i = 0, _a = unionTarget.types; _i < _a.length; _i++) {
87347
- var target = _a[_i];
87348
- var overlap = getIntersectionType([getIndexType(source), getIndexType(target)]);
87349
- if (overlap.flags & 4194304 /* Index */) {
87350
- // perfect overlap of keys
87351
- bestMatch = target;
87352
- matchingCount = Infinity;
87353
- }
87354
- else if (overlap.flags & 1048576 /* Union */) {
87355
- // We only want to account for literal types otherwise.
87356
- // If we have a union of index types, it seems likely that we
87357
- // needed to elaborate between two generic mapped types anyway.
87358
- var len = ts.length(ts.filter(overlap.types, isUnitType));
87359
- if (len >= matchingCount) {
87360
- bestMatch = target;
87361
- matchingCount = len;
87362
- }
87363
- }
87364
- else if (isUnitType(overlap) && 1 >= matchingCount) {
87365
- bestMatch = target;
87366
- matchingCount = 1;
87399
+ if (!(source.flags & (131068 /* Primitive */ | 406847488 /* InstantiablePrimitive */))) {
87400
+ var matchingCount = 0;
87401
+ for (var _i = 0, _a = unionTarget.types; _i < _a.length; _i++) {
87402
+ var target = _a[_i];
87403
+ if (!(target.flags & (131068 /* Primitive */ | 406847488 /* InstantiablePrimitive */))) {
87404
+ var overlap = getIntersectionType([getIndexType(source), getIndexType(target)]);
87405
+ if (overlap.flags & 4194304 /* Index */) {
87406
+ // perfect overlap of keys
87407
+ return target;
87408
+ }
87409
+ else if (isUnitType(overlap) || overlap.flags & 1048576 /* Union */) {
87410
+ // We only want to account for literal types otherwise.
87411
+ // If we have a union of index types, it seems likely that we
87412
+ // needed to elaborate between two generic mapped types anyway.
87413
+ var len = overlap.flags & 1048576 /* Union */ ? ts.countWhere(overlap.types, isUnitType) : 1;
87414
+ if (len >= matchingCount) {
87415
+ bestMatch = target;
87416
+ matchingCount = len;
87417
+ }
87418
+ }
87419
+ }
87367
87420
  }
87368
87421
  }
87369
87422
  return bestMatch;
@@ -106406,7 +106459,7 @@ var ts;
106406
106459
  var sourceFile = ts.createUnparsedSourceFile(prepend, "dts", stripInternal);
106407
106460
  hasNoDefaultLib_1 = hasNoDefaultLib_1 || !!sourceFile.hasNoDefaultLib;
106408
106461
  collectReferences(sourceFile, refs);
106409
- recordTypeReferenceDirectivesIfNecessary(sourceFile.typeReferenceDirectives);
106462
+ recordTypeReferenceDirectivesIfNecessary(ts.map(sourceFile.typeReferenceDirectives, function (ref) { return [ref.fileName, ref.resolutionMode]; }));
106410
106463
  collectLibs(sourceFile, libs);
106411
106464
  return sourceFile;
106412
106465
  }
@@ -106461,9 +106514,10 @@ var ts;
106461
106514
  return ts.map(ts.arrayFrom(libs.keys()), function (lib) { return ({ fileName: lib, pos: -1, end: -1 }); });
106462
106515
  }
106463
106516
  function getFileReferencesForUsedTypeReferences() {
106464
- return necessaryTypeReferences ? ts.mapDefined(ts.arrayFrom(necessaryTypeReferences.keys()), getFileReferenceForTypeName) : [];
106517
+ return necessaryTypeReferences ? ts.mapDefined(ts.arrayFrom(necessaryTypeReferences.keys()), getFileReferenceForSpecifierModeTuple) : [];
106465
106518
  }
106466
- function getFileReferenceForTypeName(typeName) {
106519
+ function getFileReferenceForSpecifierModeTuple(_a) {
106520
+ var typeName = _a[0], mode = _a[1];
106467
106521
  // Elide type references for which we have imports
106468
106522
  if (emittedImports) {
106469
106523
  for (var _i = 0, emittedImports_1 = emittedImports; _i < emittedImports_1.length; _i++) {
@@ -106479,7 +106533,7 @@ var ts;
106479
106533
  }
106480
106534
  }
106481
106535
  }
106482
- return { fileName: typeName, pos: -1, end: -1 };
106536
+ return __assign({ fileName: typeName, pos: -1, end: -1 }, (mode ? { resolutionMode: mode } : undefined));
106483
106537
  }
106484
106538
  function mapReferencesIntoArray(references, outputFilePath) {
106485
106539
  return function (file) {
@@ -106499,7 +106553,7 @@ var ts;
106499
106553
  // If some compiler option/symlink/whatever allows access to the file containing the ambient module declaration
106500
106554
  // via a non-relative name, emit a type reference directive to that non-relative name, rather than
106501
106555
  // a relative path to the declaration file
106502
- recordTypeReferenceDirectivesIfNecessary([specifier]);
106556
+ recordTypeReferenceDirectivesIfNecessary([[specifier, /*mode*/ undefined]]);
106503
106557
  return;
106504
106558
  }
106505
106559
  var fileName = ts.getRelativePathToDirectoryOrUrl(outputFilePath, declFileName, host.getCurrentDirectory(), host.getCanonicalFileName,
@@ -111611,9 +111665,12 @@ var ts;
111611
111665
  for (var _d = 0, types_24 = types; _d < types_24.length; _d++) {
111612
111666
  var directive = types_24[_d];
111613
111667
  var pos = writer.getTextPos();
111614
- writeComment("/// <reference types=\"" + directive.fileName + "\" />");
111668
+ var resolutionMode = directive.resolutionMode && directive.resolutionMode !== (currentSourceFile === null || currentSourceFile === void 0 ? void 0 : currentSourceFile.impliedNodeFormat)
111669
+ ? "resolution-mode=\"" + (directive.resolutionMode === ts.ModuleKind.ESNext ? "import" : "require") + "\""
111670
+ : "";
111671
+ writeComment("/// <reference types=\"" + directive.fileName + "\" " + resolutionMode + "/>");
111615
111672
  if (bundleFileInfo)
111616
- bundleFileInfo.sections.push({ pos: pos, end: writer.getTextPos(), kind: "type" /* Type */, data: directive.fileName });
111673
+ bundleFileInfo.sections.push({ pos: pos, end: writer.getTextPos(), kind: !directive.resolutionMode ? "type" /* Type */ : directive.resolutionMode === ts.ModuleKind.ESNext ? "type-import" /* TypeResolutionModeImport */ : "type-require" /* TypeResolutionModeRequire */, data: directive.fileName });
111617
111674
  writeLine();
111618
111675
  }
111619
111676
  for (var _e = 0, libs_1 = libs; _e < libs_1.length; _e++) {
@@ -114220,7 +114277,7 @@ var ts;
114220
114277
  }
114221
114278
  ts.flattenDiagnosticMessageText = flattenDiagnosticMessageText;
114222
114279
  /* @internal */
114223
- function loadWithLocalCache(names, containingFile, redirectedReference, loader) {
114280
+ function loadWithTypeDirectiveCache(names, containingFile, redirectedReference, containingFileMode, loader) {
114224
114281
  if (names.length === 0) {
114225
114282
  return [];
114226
114283
  }
@@ -114229,19 +114286,28 @@ var ts;
114229
114286
  for (var _i = 0, names_2 = names; _i < names_2.length; _i++) {
114230
114287
  var name = names_2[_i];
114231
114288
  var result = void 0;
114232
- if (cache.has(name)) {
114233
- result = cache.get(name);
114289
+ var mode = getModeForFileReference(name, containingFileMode);
114290
+ // We lower-case all type references because npm automatically lowercases all packages. See GH#9824.
114291
+ var strName = ts.isString(name) ? name : name.fileName.toLowerCase();
114292
+ var cacheKey = mode !== undefined ? mode + "|" + strName : strName;
114293
+ if (cache.has(cacheKey)) {
114294
+ result = cache.get(cacheKey);
114234
114295
  }
114235
114296
  else {
114236
- cache.set(name, result = loader(name, containingFile, redirectedReference));
114297
+ cache.set(cacheKey, result = loader(strName, containingFile, redirectedReference, mode));
114237
114298
  }
114238
114299
  resolutions.push(result);
114239
114300
  }
114240
114301
  return resolutions;
114241
114302
  }
114242
- ts.loadWithLocalCache = loadWithLocalCache;
114303
+ ts.loadWithTypeDirectiveCache = loadWithTypeDirectiveCache;
114243
114304
  ;
114244
114305
  /* @internal */
114306
+ function getModeForFileReference(ref, containingFileMode) {
114307
+ return (ts.isString(ref) ? containingFileMode : ref.resolutionMode) || containingFileMode;
114308
+ }
114309
+ ts.getModeForFileReference = getModeForFileReference;
114310
+ /* @internal */
114245
114311
  function getModeForResolutionAtIndex(file, index) {
114246
114312
  if (file.impliedNodeFormat === undefined)
114247
114313
  return undefined;
@@ -114344,7 +114410,7 @@ var ts;
114344
114410
  var _d, _e, _f, _g;
114345
114411
  var file = ts.Debug.checkDefined(getSourceFileByPath(ref.file));
114346
114412
  var kind = ref.kind, index = ref.index;
114347
- var pos, end, packageId;
114413
+ var pos, end, packageId, resolutionMode;
114348
114414
  switch (kind) {
114349
114415
  case ts.FileIncludeKind.Import:
114350
114416
  var importLiteral = getModuleNameStringLiteralAt(file, index);
@@ -114358,8 +114424,8 @@ var ts;
114358
114424
  (_a = file.referencedFiles[index], pos = _a.pos, end = _a.end);
114359
114425
  break;
114360
114426
  case ts.FileIncludeKind.TypeReferenceDirective:
114361
- (_b = file.typeReferenceDirectives[index], pos = _b.pos, end = _b.end);
114362
- packageId = (_g = (_f = file.resolvedTypeReferenceDirectiveNames) === null || _f === void 0 ? void 0 : _f.get(ts.toFileNameLowerCase(file.typeReferenceDirectives[index].fileName), file.impliedNodeFormat)) === null || _g === void 0 ? void 0 : _g.packageId;
114427
+ (_b = file.typeReferenceDirectives[index], pos = _b.pos, end = _b.end, resolutionMode = _b.resolutionMode);
114428
+ packageId = (_g = (_f = file.resolvedTypeReferenceDirectiveNames) === null || _f === void 0 ? void 0 : _f.get(ts.toFileNameLowerCase(file.typeReferenceDirectives[index].fileName), resolutionMode || file.impliedNodeFormat)) === null || _g === void 0 ? void 0 : _g.packageId;
114363
114429
  break;
114364
114430
  case ts.FileIncludeKind.LibReferenceDirective:
114365
114431
  (_c = file.libReferenceDirectives[index], pos = _c.pos, end = _c.end);
@@ -114603,7 +114669,7 @@ var ts;
114603
114669
  var fileReasons = ts.createMultiMap();
114604
114670
  var cachedBindAndCheckDiagnosticsForFile = {};
114605
114671
  var cachedDeclarationDiagnosticsForFile = {};
114606
- var resolvedTypeReferenceDirectives = new ts.Map();
114672
+ var resolvedTypeReferenceDirectives = ts.createModeAwareCache();
114607
114673
  var fileProcessingDiagnostics;
114608
114674
  // The below settings are to track if a .js file should be add to the program if loaded via searching under node_modules.
114609
114675
  // This works as imported modules are discovered recursively in a depth first manner, specifically:
@@ -114656,12 +114722,12 @@ var ts;
114656
114722
  }
114657
114723
  var actualResolveTypeReferenceDirectiveNamesWorker;
114658
114724
  if (host.resolveTypeReferenceDirectives) {
114659
- actualResolveTypeReferenceDirectiveNamesWorker = function (typeDirectiveNames, containingFile, redirectedReference) { return host.resolveTypeReferenceDirectives(ts.Debug.checkEachDefined(typeDirectiveNames), containingFile, redirectedReference, options); };
114725
+ actualResolveTypeReferenceDirectiveNamesWorker = function (typeDirectiveNames, containingFile, redirectedReference, containingFileMode) { return host.resolveTypeReferenceDirectives(ts.Debug.checkEachDefined(typeDirectiveNames), containingFile, redirectedReference, options, containingFileMode); };
114660
114726
  }
114661
114727
  else {
114662
114728
  typeReferenceDirectiveResolutionCache = ts.createTypeReferenceDirectiveResolutionCache(currentDirectory, getCanonicalFileName, /*options*/ undefined, moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache());
114663
- var loader_2 = function (typesRef, containingFile, redirectedReference) { return ts.resolveTypeReferenceDirective(typesRef, containingFile, options, host, redirectedReference, typeReferenceDirectiveResolutionCache).resolvedTypeReferenceDirective; }; // TODO: GH#18217
114664
- actualResolveTypeReferenceDirectiveNamesWorker = function (typeReferenceDirectiveNames, containingFile, redirectedReference) { return loadWithLocalCache(ts.Debug.checkEachDefined(typeReferenceDirectiveNames), containingFile, redirectedReference, loader_2); };
114729
+ var loader_2 = function (typesRef, containingFile, redirectedReference, resolutionMode) { return ts.resolveTypeReferenceDirective(typesRef, containingFile, options, host, redirectedReference, typeReferenceDirectiveResolutionCache, resolutionMode).resolvedTypeReferenceDirective; }; // TODO: GH#18217
114730
+ actualResolveTypeReferenceDirectiveNamesWorker = function (typeReferenceDirectiveNames, containingFile, redirectedReference, containingFileMode) { return loadWithTypeDirectiveCache(ts.Debug.checkEachDefined(typeReferenceDirectiveNames), containingFile, redirectedReference, containingFileMode, loader_2); };
114665
114731
  }
114666
114732
  // Map from a stringified PackageId to the source file with that id.
114667
114733
  // Only one source file may have a given packageId. Others become redirects (see createRedirectSourceFile).
@@ -114758,7 +114824,8 @@ var ts;
114758
114824
  var containingFilename = ts.combinePaths(containingDirectory, ts.inferredTypesContainingFile);
114759
114825
  var resolutions = resolveTypeReferenceDirectiveNamesWorker(typeReferences, containingFilename);
114760
114826
  for (var i = 0; i < typeReferences.length; i++) {
114761
- processTypeReferenceDirective(typeReferences[i], resolutions[i], { kind: ts.FileIncludeKind.AutomaticTypeDirectiveFile, typeReference: typeReferences[i], packageId: (_c = resolutions[i]) === null || _c === void 0 ? void 0 : _c.packageId });
114827
+ // under node12/nodenext module resolution, load `types`/ata include names as cjs resolution results by passing an `undefined` mode
114828
+ processTypeReferenceDirective(typeReferences[i], /*mode*/ undefined, resolutions[i], { kind: ts.FileIncludeKind.AutomaticTypeDirectiveFile, typeReference: typeReferences[i], packageId: (_c = resolutions[i]) === null || _c === void 0 ? void 0 : _c.packageId });
114762
114829
  }
114763
114830
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
114764
114831
  }
@@ -114918,9 +114985,10 @@ var ts;
114918
114985
  return [];
114919
114986
  var containingFileName = !ts.isString(containingFile) ? ts.getNormalizedAbsolutePath(containingFile.originalFileName, currentDirectory) : containingFile;
114920
114987
  var redirectedReference = !ts.isString(containingFile) ? getRedirectReferenceForResolution(containingFile) : undefined;
114988
+ var containingFileMode = !ts.isString(containingFile) ? containingFile.impliedNodeFormat : undefined;
114921
114989
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("program" /* Program */, "resolveTypeReferenceDirectiveNamesWorker", { containingFileName: containingFileName });
114922
114990
  ts.performance.mark("beforeResolveTypeReference");
114923
- var result = actualResolveTypeReferenceDirectiveNamesWorker(typeDirectiveNames, containingFileName, redirectedReference);
114991
+ var result = actualResolveTypeReferenceDirectiveNamesWorker(typeDirectiveNames, containingFileName, redirectedReference, containingFileMode);
114924
114992
  ts.performance.mark("afterResolveTypeReference");
114925
114993
  ts.performance.measure("ResolveTypeReference", "beforeResolveTypeReference", "afterResolveTypeReference");
114926
114994
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
@@ -115312,8 +115380,7 @@ var ts;
115312
115380
  else {
115313
115381
  newSourceFile.resolvedModules = oldSourceFile.resolvedModules;
115314
115382
  }
115315
- // We lower-case all type references because npm automatically lowercases all packages. See GH#9824.
115316
- var typesReferenceDirectives = ts.map(newSourceFile.typeReferenceDirectives, function (ref) { return ts.toFileNameLowerCase(ref.fileName); });
115383
+ var typesReferenceDirectives = newSourceFile.typeReferenceDirectives;
115317
115384
  var typeReferenceResolutions = resolveTypeReferenceDirectiveNamesWorker(typesReferenceDirectives, newSourceFile);
115318
115385
  // ensure that types resolutions are still correct
115319
115386
  var typeReferenceResolutionsChanged = ts.hasChangesInResolutions(typesReferenceDirectives, typeReferenceResolutions, oldSourceFile.resolvedTypeReferenceDirectiveNames, oldSourceFile, ts.typeDirectiveIsEqualTo);
@@ -116392,8 +116459,7 @@ var ts;
116392
116459
  });
116393
116460
  }
116394
116461
  function processTypeReferenceDirectives(file) {
116395
- // We lower-case all type references because npm automatically lowercases all packages. See GH#9824.
116396
- var typeDirectives = ts.map(file.typeReferenceDirectives, function (ref) { return ts.toFileNameLowerCase(ref.fileName); });
116462
+ var typeDirectives = file.typeReferenceDirectives;
116397
116463
  if (!typeDirectives) {
116398
116464
  return;
116399
116465
  }
@@ -116404,17 +116470,21 @@ var ts;
116404
116470
  // store resolved type directive on the file
116405
116471
  var fileName = ts.toFileNameLowerCase(ref.fileName);
116406
116472
  ts.setResolvedTypeReferenceDirective(file, fileName, resolvedTypeReferenceDirective);
116407
- processTypeReferenceDirective(fileName, resolvedTypeReferenceDirective, { kind: ts.FileIncludeKind.TypeReferenceDirective, file: file.path, index: index, });
116473
+ var mode = ref.resolutionMode || file.impliedNodeFormat;
116474
+ if (mode && ts.getEmitModuleResolutionKind(options) !== ts.ModuleResolutionKind.Node12 && ts.getEmitModuleResolutionKind(options) !== ts.ModuleResolutionKind.NodeNext) {
116475
+ programDiagnostics.add(ts.createDiagnosticForRange(file, ref, ts.Diagnostics.Resolution_modes_are_only_supported_when_moduleResolution_is_node12_or_nodenext));
116476
+ }
116477
+ processTypeReferenceDirective(fileName, mode, resolvedTypeReferenceDirective, { kind: ts.FileIncludeKind.TypeReferenceDirective, file: file.path, index: index, });
116408
116478
  }
116409
116479
  }
116410
- function processTypeReferenceDirective(typeReferenceDirective, resolvedTypeReferenceDirective, reason) {
116480
+ function processTypeReferenceDirective(typeReferenceDirective, mode, resolvedTypeReferenceDirective, reason) {
116411
116481
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("program" /* Program */, "processTypeReferenceDirective", { directive: typeReferenceDirective, hasResolved: !!resolveModuleNamesReusingOldState, refKind: reason.kind, refPath: isReferencedFile(reason) ? reason.file : undefined });
116412
- processTypeReferenceDirectiveWorker(typeReferenceDirective, resolvedTypeReferenceDirective, reason);
116482
+ processTypeReferenceDirectiveWorker(typeReferenceDirective, mode, resolvedTypeReferenceDirective, reason);
116413
116483
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
116414
116484
  }
116415
- function processTypeReferenceDirectiveWorker(typeReferenceDirective, resolvedTypeReferenceDirective, reason) {
116485
+ function processTypeReferenceDirectiveWorker(typeReferenceDirective, mode, resolvedTypeReferenceDirective, reason) {
116416
116486
  // If we already found this library as a primary reference - nothing to do
116417
- var previousResolution = resolvedTypeReferenceDirectives.get(typeReferenceDirective);
116487
+ var previousResolution = resolvedTypeReferenceDirectives.get(typeReferenceDirective, mode);
116418
116488
  if (previousResolution && previousResolution.primary) {
116419
116489
  return;
116420
116490
  }
@@ -116453,7 +116523,7 @@ var ts;
116453
116523
  addFilePreprocessingFileExplainingDiagnostic(/*file*/ undefined, reason, ts.Diagnostics.Cannot_find_type_definition_file_for_0, [typeReferenceDirective]);
116454
116524
  }
116455
116525
  if (saveResolution) {
116456
- resolvedTypeReferenceDirectives.set(typeReferenceDirective, resolvedTypeReferenceDirective);
116526
+ resolvedTypeReferenceDirectives.set(typeReferenceDirective, mode, resolvedTypeReferenceDirective);
116457
116527
  }
116458
116528
  }
116459
116529
  function pathForLibFile(libFileName) {
@@ -119271,9 +119341,9 @@ var ts;
119271
119341
  });
119272
119342
  hasChangedAutomaticTypeDirectiveNames = false;
119273
119343
  }
119274
- function resolveModuleName(moduleName, containingFile, compilerOptions, host, redirectedReference) {
119344
+ function resolveModuleName(moduleName, containingFile, compilerOptions, host, redirectedReference, _containingSourceFile, mode) {
119275
119345
  var _a;
119276
- var primaryResult = ts.resolveModuleName(moduleName, containingFile, compilerOptions, host, moduleResolutionCache, redirectedReference);
119346
+ var primaryResult = ts.resolveModuleName(moduleName, containingFile, compilerOptions, host, moduleResolutionCache, redirectedReference, mode);
119277
119347
  // return result immediately only if global cache support is not enabled or if it is .ts, .tsx or .d.ts
119278
119348
  if (!resolutionHost.getGlobalCache) {
119279
119349
  return primaryResult;
@@ -119294,12 +119364,12 @@ var ts;
119294
119364
  // Default return the result from the first pass
119295
119365
  return primaryResult;
119296
119366
  }
119297
- function resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference) {
119298
- return ts.resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference, typeReferenceDirectiveResolutionCache);
119367
+ function resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference, _containingSourceFile, resolutionMode) {
119368
+ return ts.resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference, typeReferenceDirectiveResolutionCache, resolutionMode);
119299
119369
  }
119300
119370
  function resolveNamesWithLocalCache(_a) {
119301
119371
  var _b, _c, _d;
119302
- var names = _a.names, containingFile = _a.containingFile, redirectedReference = _a.redirectedReference, cache = _a.cache, perDirectoryCacheWithRedirects = _a.perDirectoryCacheWithRedirects, loader = _a.loader, getResolutionWithResolvedFileName = _a.getResolutionWithResolvedFileName, shouldRetryResolution = _a.shouldRetryResolution, reusedNames = _a.reusedNames, logChanges = _a.logChanges, containingSourceFile = _a.containingSourceFile;
119372
+ var names = _a.names, containingFile = _a.containingFile, redirectedReference = _a.redirectedReference, cache = _a.cache, perDirectoryCacheWithRedirects = _a.perDirectoryCacheWithRedirects, loader = _a.loader, getResolutionWithResolvedFileName = _a.getResolutionWithResolvedFileName, shouldRetryResolution = _a.shouldRetryResolution, reusedNames = _a.reusedNames, logChanges = _a.logChanges, containingSourceFile = _a.containingSourceFile, containingSourceFileMode = _a.containingSourceFileMode;
119303
119373
  var path = resolutionHost.toPath(containingFile);
119304
119374
  var resolutionsInFile = cache.get(path) || cache.set(path, ts.createModeAwareCache()).get(path);
119305
119375
  var dirPath = ts.getDirectoryPath(path);
@@ -119321,8 +119391,15 @@ var ts;
119321
119391
  var seenNamesInFile = ts.createModeAwareCache();
119322
119392
  var i = 0;
119323
119393
  for (var _i = 0, names_4 = names; _i < names_4.length; _i++) {
119324
- var name = names_4[_i];
119325
- var mode = containingSourceFile ? ts.getModeForResolutionAtIndex(containingSourceFile, i) : undefined;
119394
+ var entry = names_4[_i];
119395
+ var name = ts.isString(entry) ? entry : entry.fileName.toLowerCase();
119396
+ // Imports supply a `containingSourceFile` but no `containingSourceFileMode` - it would be redundant
119397
+ // they require calculating the mode for a given import from it's position in the resolution table, since a given
119398
+ // import's syntax may override the file's default mode.
119399
+ // Type references instead supply a `containingSourceFileMode` and a non-string entry which contains
119400
+ // a default file mode override if applicable.
119401
+ var mode = !ts.isString(entry) ? ts.getModeForFileReference(entry, containingSourceFileMode) :
119402
+ containingSourceFile ? ts.getModeForResolutionAtIndex(containingSourceFile, i) : undefined;
119326
119403
  i++;
119327
119404
  var resolution = resolutionsInFile.get(name, mode);
119328
119405
  // Resolution is valid if it is present and not invalidated
@@ -119351,7 +119428,7 @@ var ts;
119351
119428
  }
119352
119429
  }
119353
119430
  else {
119354
- resolution = loader(name, containingFile, compilerOptions, ((_c = resolutionHost.getCompilerHost) === null || _c === void 0 ? void 0 : _c.call(resolutionHost)) || resolutionHost, redirectedReference, containingSourceFile);
119431
+ resolution = loader(name, containingFile, compilerOptions, ((_c = resolutionHost.getCompilerHost) === null || _c === void 0 ? void 0 : _c.call(resolutionHost)) || resolutionHost, redirectedReference, containingSourceFile, mode);
119355
119432
  perDirectoryResolution.set(name, mode, resolution);
119356
119433
  if (resolutionHost.onDiscoveredSymlink && resolutionIsSymlink(resolution)) {
119357
119434
  resolutionHost.onDiscoveredSymlink();
@@ -119415,7 +119492,7 @@ var ts;
119415
119492
  return oldResult.resolvedFileName === newResult.resolvedFileName;
119416
119493
  }
119417
119494
  }
119418
- function resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference) {
119495
+ function resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference, containingFileMode) {
119419
119496
  return resolveNamesWithLocalCache({
119420
119497
  names: typeDirectiveNames,
119421
119498
  containingFile: containingFile,
@@ -119425,6 +119502,7 @@ var ts;
119425
119502
  loader: resolveTypeReferenceDirective,
119426
119503
  getResolutionWithResolvedFileName: getResolvedTypeReferenceDirective,
119427
119504
  shouldRetryResolution: function (resolution) { return resolution.resolvedTypeReferenceDirective === undefined; },
119505
+ containingSourceFileMode: containingFileMode
119428
119506
  });
119429
119507
  }
119430
119508
  function resolveModuleNames(moduleNames, containingFile, reusedNames, redirectedReference, containingSourceFile) {
@@ -121333,7 +121411,7 @@ var ts;
121333
121411
  }
121334
121412
  return host.resolveTypeReferenceDirectives.apply(host, args);
121335
121413
  }) :
121336
- (function (typeDirectiveNames, containingFile, redirectedReference) { return resolutionCache.resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference); });
121414
+ (function (typeDirectiveNames, containingFile, redirectedReference, _options, containingFileMode) { return resolutionCache.resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference, containingFileMode); });
121337
121415
  var userProvidedResolution = !!host.resolveModuleNames || !!host.resolveTypeReferenceDirectives;
121338
121416
  builderProgram = readBuilderProgram(compilerOptions, compilerHost);
121339
121417
  synchronizeProgram();
@@ -122069,9 +122147,9 @@ var ts;
122069
122147
  compilerHost.getModuleResolutionCache = function () { return moduleResolutionCache; };
122070
122148
  }
122071
122149
  if (!compilerHost.resolveTypeReferenceDirectives) {
122072
- var loader_4 = function (moduleName, containingFile, redirectedReference) { return ts.resolveTypeReferenceDirective(moduleName, containingFile, state.projectCompilerOptions, compilerHost, redirectedReference, state.typeReferenceDirectiveResolutionCache).resolvedTypeReferenceDirective; };
122073
- compilerHost.resolveTypeReferenceDirectives = function (typeReferenceDirectiveNames, containingFile, redirectedReference) {
122074
- return ts.loadWithLocalCache(ts.Debug.checkEachDefined(typeReferenceDirectiveNames), containingFile, redirectedReference, loader_4);
122150
+ var loader_4 = function (moduleName, containingFile, redirectedReference, containingFileMode) { return ts.resolveTypeReferenceDirective(moduleName, containingFile, state.projectCompilerOptions, compilerHost, redirectedReference, state.typeReferenceDirectiveResolutionCache, containingFileMode).resolvedTypeReferenceDirective; };
122151
+ compilerHost.resolveTypeReferenceDirectives = function (typeReferenceDirectiveNames, containingFile, redirectedReference, _options, containingFileMode) {
122152
+ return ts.loadWithTypeDirectiveCache(ts.Debug.checkEachDefined(typeReferenceDirectiveNames), containingFile, redirectedReference, containingFileMode, loader_4);
122075
122153
  };
122076
122154
  }
122077
122155
  var _a = ts.createWatchFactory(hostWithWatch, options), watchFile = _a.watchFile, watchDirectory = _a.watchDirectory, writeLog = _a.writeLog;
@@ -130622,14 +130700,15 @@ var ts;
130622
130700
  if (tag.tagName.pos <= position && position <= tag.tagName.end) {
130623
130701
  return { kind: 1 /* JsDocTagName */ };
130624
130702
  }
130625
- if (isTagWithTypeExpression(tag) && tag.typeExpression && tag.typeExpression.kind === 307 /* JSDocTypeExpression */) {
130703
+ var typeExpression = tryGetTypeExpressionFromTag(tag);
130704
+ if (typeExpression) {
130626
130705
  currentToken = ts.getTokenAtPosition(sourceFile, position);
130627
130706
  if (!currentToken ||
130628
130707
  (!ts.isDeclarationName(currentToken) &&
130629
130708
  (currentToken.parent.kind !== 345 /* JSDocPropertyTag */ ||
130630
130709
  currentToken.parent.name !== currentToken))) {
130631
130710
  // Use as type location if inside tag's type expression
130632
- insideJsDocTagTypeExpression = isCurrentlyEditingNode(tag.typeExpression);
130711
+ insideJsDocTagTypeExpression = isCurrentlyEditingNode(typeExpression);
130633
130712
  }
130634
130713
  }
130635
130714
  if (!insideJsDocTagTypeExpression && ts.isJSDocParameterTag(tag) && (ts.nodeIsMissing(tag.name) || tag.name.pos <= position && position <= tag.name.end)) {
@@ -130886,10 +130965,19 @@ var ts;
130886
130965
  case 341 /* JSDocTypeTag */:
130887
130966
  case 343 /* JSDocTypedefTag */:
130888
130967
  return true;
130968
+ case 342 /* JSDocTemplateTag */:
130969
+ return !!tag.constraint;
130889
130970
  default:
130890
130971
  return false;
130891
130972
  }
130892
130973
  }
130974
+ function tryGetTypeExpressionFromTag(tag) {
130975
+ if (isTagWithTypeExpression(tag)) {
130976
+ var typeExpression = ts.isJSDocTemplateTag(tag) ? tag.constraint : tag.typeExpression;
130977
+ return typeExpression && typeExpression.kind === 307 /* JSDocTypeExpression */ ? typeExpression : undefined;
130978
+ }
130979
+ return undefined;
130980
+ }
130893
130981
  function getTypeScriptMemberSymbols() {
130894
130982
  // Right of dot member completion list
130895
130983
  completionKind = 2 /* PropertyAccess */;
@@ -133645,7 +133733,7 @@ var ts;
133645
133733
  }
133646
133734
  for (var _c = 0, _d = referencingFile.typeReferenceDirectives; _c < _d.length; _c++) {
133647
133735
  var ref = _d[_c];
133648
- var referenced = program.getResolvedTypeReferenceDirectives().get(ref.fileName);
133736
+ var referenced = program.getResolvedTypeReferenceDirectives().get(ref.fileName, ref.resolutionMode || referencingFile.impliedNodeFormat);
133649
133737
  if (referenced !== undefined && referenced.resolvedFileName === searchSourceFile.fileName) {
133650
133738
  refs.push({ kind: "reference", referencingFile: referencingFile, ref: ref });
133651
133739
  }
@@ -136867,7 +136955,7 @@ var ts;
136867
136955
  }
136868
136956
  var typeReferenceDirective = findReferenceInPosition(sourceFile.typeReferenceDirectives, position);
136869
136957
  if (typeReferenceDirective) {
136870
- var reference = program.getResolvedTypeReferenceDirectives().get(typeReferenceDirective.fileName);
136958
+ var reference = program.getResolvedTypeReferenceDirectives().get(typeReferenceDirective.fileName, typeReferenceDirective.resolutionMode || sourceFile.impliedNodeFormat);
136871
136959
  var file = reference && program.getSourceFile(reference.resolvedFileName); // TODO:GH#18217
136872
136960
  return file && { reference: typeReferenceDirective, fileName: file.fileName, file: file, unverified: false };
136873
136961
  }
@@ -163689,7 +163777,7 @@ var ts;
163689
163777
  if ("getTypeReferenceDirectiveResolutionsForFile" in this.shimHost) {
163690
163778
  this.resolveTypeReferenceDirectives = function (typeDirectiveNames, containingFile) {
163691
163779
  var typeDirectivesForFile = JSON.parse(_this.shimHost.getTypeReferenceDirectiveResolutionsForFile(containingFile)); // TODO: GH#18217
163692
- return ts.map(typeDirectiveNames, function (name) { return ts.getProperty(typeDirectivesForFile, name); });
163780
+ return ts.map(typeDirectiveNames, function (name) { return ts.getProperty(typeDirectivesForFile, ts.isString(name) ? name : name.fileName.toLowerCase()); });
163693
163781
  };
163694
163782
  }
163695
163783
  }
@@ -166388,8 +166476,8 @@ var ts;
166388
166476
  Project.prototype.getResolvedModuleWithFailedLookupLocationsFromCache = function (moduleName, containingFile, resolutionMode) {
166389
166477
  return this.resolutionCache.getResolvedModuleWithFailedLookupLocationsFromCache(moduleName, containingFile, resolutionMode);
166390
166478
  };
166391
- Project.prototype.resolveTypeReferenceDirectives = function (typeDirectiveNames, containingFile, redirectedReference) {
166392
- return this.resolutionCache.resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference);
166479
+ Project.prototype.resolveTypeReferenceDirectives = function (typeDirectiveNames, containingFile, redirectedReference, _options, containingFileMode) {
166480
+ return this.resolutionCache.resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference, containingFileMode);
166393
166481
  };
166394
166482
  Project.prototype.directoryExists = function (path) {
166395
166483
  return this.directoryStructureHost.directoryExists(path); // TODO: GH#18217