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.
@@ -89,7 +89,7 @@ var ts;
89
89
  // The following is baselined as a literal template type without intervention
90
90
  /** The version of the TypeScript compiler release */
91
91
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
92
- ts.version = ts.versionMajorMinor + ".0-dev.20220215";
92
+ ts.version = ts.versionMajorMinor + ".0-dev.20220216";
93
93
  /* @internal */
94
94
  var Comparison;
95
95
  (function (Comparison) {
@@ -4829,6 +4829,8 @@ var ts;
4829
4829
  TypeFlags[TypeFlags["ESSymbolLike"] = 12288] = "ESSymbolLike";
4830
4830
  TypeFlags[TypeFlags["VoidLike"] = 49152] = "VoidLike";
4831
4831
  /* @internal */
4832
+ TypeFlags[TypeFlags["DefinitelyNonNullable"] = 470302716] = "DefinitelyNonNullable";
4833
+ /* @internal */
4832
4834
  TypeFlags[TypeFlags["DisjointDomains"] = 469892092] = "DisjointDomains";
4833
4835
  TypeFlags[TypeFlags["UnionOrIntersection"] = 3145728] = "UnionOrIntersection";
4834
4836
  TypeFlags[TypeFlags["StructuredType"] = 3670016] = "StructuredType";
@@ -5561,6 +5563,8 @@ var ts;
5561
5563
  BundleFileSectionKind["NoDefaultLib"] = "no-default-lib";
5562
5564
  BundleFileSectionKind["Reference"] = "reference";
5563
5565
  BundleFileSectionKind["Type"] = "type";
5566
+ BundleFileSectionKind["TypeResolutionModeRequire"] = "type-require";
5567
+ BundleFileSectionKind["TypeResolutionModeImport"] = "type-import";
5564
5568
  BundleFileSectionKind["Lib"] = "lib";
5565
5569
  BundleFileSectionKind["Prepend"] = "prepend";
5566
5570
  BundleFileSectionKind["Text"] = "text";
@@ -5677,7 +5681,8 @@ var ts;
5677
5681
  { name: "types", optional: true, captureSpan: true },
5678
5682
  { name: "lib", optional: true, captureSpan: true },
5679
5683
  { name: "path", optional: true, captureSpan: true },
5680
- { name: "no-default-lib", optional: true }
5684
+ { name: "no-default-lib", optional: true },
5685
+ { name: "resolution-mode", optional: true }
5681
5686
  ],
5682
5687
  kind: 1 /* TripleSlashXML */
5683
5688
  },
@@ -8058,6 +8063,8 @@ var ts;
8058
8063
  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."),
8059
8064
  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."),
8060
8065
  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."),
8066
+ 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}'."),
8067
+ 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'."),
8061
8068
  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."),
8062
8069
  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."),
8063
8070
  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."),
@@ -8191,6 +8198,8 @@ var ts;
8191
8198
  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."),
8192
8199
  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"),
8193
8200
  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"),
8201
+ 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`."),
8202
+ 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`."),
8194
8203
  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."),
8195
8204
  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."),
8196
8205
  catch_or_finally_expected: diag(1472, ts.DiagnosticCategory.Error, "catch_or_finally_expected_1472", "'catch' or 'finally' expected."),
@@ -14074,7 +14083,11 @@ var ts;
14074
14083
  ts.Debug.assert(names.length === newResolutions.length);
14075
14084
  for (var i = 0; i < names.length; i++) {
14076
14085
  var newResolution = newResolutions[i];
14077
- var oldResolution = oldResolutions && oldResolutions.get(names[i], oldSourceFile && ts.getModeForResolutionAtIndex(oldSourceFile, i));
14086
+ var entry = names[i];
14087
+ // We lower-case all type references because npm automatically lowercases all packages. See GH#9824.
14088
+ var name = !ts.isString(entry) ? entry.fileName.toLowerCase() : entry;
14089
+ var mode = !ts.isString(entry) ? ts.getModeForFileReference(entry, oldSourceFile === null || oldSourceFile === void 0 ? void 0 : oldSourceFile.impliedNodeFormat) : oldSourceFile && ts.getModeForResolutionAtIndex(oldSourceFile, i);
14090
+ var oldResolution = oldResolutions && oldResolutions.get(name, mode);
14078
14091
  var changed = oldResolution
14079
14092
  ? !newResolution || !comparer(oldResolution, newResolution)
14080
14093
  : newResolution;
@@ -26669,7 +26682,13 @@ var ts;
26669
26682
  referencedFiles = ts.append(referencedFiles, { pos: -1, end: -1, fileName: section.data });
26670
26683
  break;
26671
26684
  case "type" /* Type */:
26672
- typeReferenceDirectives = ts.append(typeReferenceDirectives, section.data);
26685
+ typeReferenceDirectives = ts.append(typeReferenceDirectives, { pos: -1, end: -1, fileName: section.data });
26686
+ break;
26687
+ case "type-import" /* TypeResolutionModeImport */:
26688
+ typeReferenceDirectives = ts.append(typeReferenceDirectives, { pos: -1, end: -1, fileName: section.data, resolutionMode: ts.ModuleKind.ESNext });
26689
+ break;
26690
+ case "type-require" /* TypeResolutionModeRequire */:
26691
+ typeReferenceDirectives = ts.append(typeReferenceDirectives, { pos: -1, end: -1, fileName: section.data, resolutionMode: ts.ModuleKind.CommonJS });
26673
26692
  break;
26674
26693
  case "lib" /* Lib */:
26675
26694
  libReferenceDirectives = ts.append(libReferenceDirectives, { pos: -1, end: -1, fileName: section.data });
@@ -26728,6 +26747,8 @@ var ts;
26728
26747
  case "no-default-lib" /* NoDefaultLib */:
26729
26748
  case "reference" /* Reference */:
26730
26749
  case "type" /* Type */:
26750
+ case "type-import" /* TypeResolutionModeImport */:
26751
+ case "type-require" /* TypeResolutionModeRequire */:
26731
26752
  case "lib" /* Lib */:
26732
26753
  syntheticReferences = ts.append(syntheticReferences, ts.setTextRange(ts.factory.createUnparsedSyntheticReference(section), section));
26733
26754
  break;
@@ -30641,7 +30662,7 @@ var ts;
30641
30662
  initializeState("", content, languageVersion, /*syntaxCursor*/ undefined, 1 /* JS */);
30642
30663
  // Prime the scanner.
30643
30664
  nextToken();
30644
- var entityName = parseEntityName(/*allowReservedWords*/ true);
30665
+ var entityName = parseEntityName(/*allowReservedWords*/ true, /*allowPrivateIdentifiers*/ false);
30645
30666
  var isInvalid = token() === 1 /* EndOfFileToken */ && !parseDiagnostics.length;
30646
30667
  clearState();
30647
30668
  return isInvalid ? entityName : undefined;
@@ -32218,7 +32239,7 @@ var ts;
32218
32239
  }
32219
32240
  return createMissingList();
32220
32241
  }
32221
- function parseEntityName(allowReservedWords, diagnosticMessage) {
32242
+ function parseEntityName(allowReservedWords, allowPrivateIdentifiers, diagnosticMessage) {
32222
32243
  var pos = getNodePos();
32223
32244
  var entity = allowReservedWords ? parseIdentifierName(diagnosticMessage) : parseIdentifier(diagnosticMessage);
32224
32245
  var dotPos = getNodePos();
@@ -32229,7 +32250,7 @@ var ts;
32229
32250
  break;
32230
32251
  }
32231
32252
  dotPos = getNodePos();
32232
- entity = finishNode(factory.createQualifiedName(entity, parseRightSideOfDot(allowReservedWords, /* allowPrivateIdentifiers */ false)), pos);
32253
+ entity = finishNode(factory.createQualifiedName(entity, parseRightSideOfDot(allowReservedWords, allowPrivateIdentifiers)), pos);
32233
32254
  }
32234
32255
  return entity;
32235
32256
  }
@@ -32362,7 +32383,7 @@ var ts;
32362
32383
  }
32363
32384
  // TYPES
32364
32385
  function parseEntityNameOfTypeReference() {
32365
- return parseEntityName(/*allowReservedWords*/ true, ts.Diagnostics.Type_expected);
32386
+ return parseEntityName(/*allowReservedWords*/ true, /*allowPrivateIdentifiers*/ false, ts.Diagnostics.Type_expected);
32366
32387
  }
32367
32388
  function parseTypeArgumentsOfTypeReference() {
32368
32389
  if (!scanner.hasPrecedingLineBreak() && reScanLessThanToken() === 29 /* LessThanToken */) {
@@ -32495,7 +32516,7 @@ var ts;
32495
32516
  function parseTypeQuery() {
32496
32517
  var pos = getNodePos();
32497
32518
  parseExpected(112 /* TypeOfKeyword */);
32498
- return finishNode(factory.createTypeQueryNode(parseEntityName(/*allowReservedWords*/ true)), pos);
32519
+ return finishNode(factory.createTypeQueryNode(parseEntityName(/*allowReservedWords*/ true, /*allowPrivateIdentifiers*/ true)), pos);
32499
32520
  }
32500
32521
  function parseTypeParameter() {
32501
32522
  var pos = getNodePos();
@@ -35066,11 +35087,12 @@ var ts;
35066
35087
  }
35067
35088
  function parseCaseClause() {
35068
35089
  var pos = getNodePos();
35090
+ var hasJSDoc = hasPrecedingJSDocComment();
35069
35091
  parseExpected(82 /* CaseKeyword */);
35070
35092
  var expression = allowInAnd(parseExpression);
35071
35093
  parseExpected(58 /* ColonToken */);
35072
35094
  var statements = parseList(3 /* SwitchClauseStatements */, parseStatement);
35073
- return finishNode(factory.createCaseClause(expression, statements), pos);
35095
+ return withJSDoc(finishNode(factory.createCaseClause(expression, statements), pos), hasJSDoc);
35074
35096
  }
35075
35097
  function parseDefaultClause() {
35076
35098
  var pos = getNodePos();
@@ -36233,7 +36255,7 @@ var ts;
36233
36255
  function parseModuleReference() {
36234
36256
  return isExternalModuleReference()
36235
36257
  ? parseExternalModuleReference()
36236
- : parseEntityName(/*allowReservedWords*/ false);
36258
+ : parseEntityName(/*allowReservedWords*/ false, /*allowPrivateIdentifiers*/ false);
36237
36259
  }
36238
36260
  function parseExternalModuleReference() {
36239
36261
  var pos = getNodePos();
@@ -36515,7 +36537,7 @@ var ts;
36515
36537
  var pos = getNodePos();
36516
36538
  var hasBrace = parseOptional(18 /* OpenBraceToken */);
36517
36539
  var p2 = getNodePos();
36518
- var entityName = parseEntityName(/* allowReservedWords*/ false);
36540
+ var entityName = parseEntityName(/* allowReservedWords*/ false, /*allowPrivateIdentifiers*/ false);
36519
36541
  while (token() === 80 /* PrivateIdentifier */) {
36520
36542
  reScanHashToken(); // rescan #id as # id
36521
36543
  nextTokenJSDoc(); // then skip the #
@@ -36958,7 +36980,7 @@ var ts;
36958
36980
  // parseEntityName logs an error for non-identifier, so create a MissingNode ourselves to avoid the error
36959
36981
  var p2 = getNodePos();
36960
36982
  var name = ts.tokenIsIdentifierOrKeyword(token())
36961
- ? parseEntityName(/*allowReservedWords*/ true)
36983
+ ? parseEntityName(/*allowReservedWords*/ true, /*allowPrivateIdentifiers*/ false)
36962
36984
  : undefined;
36963
36985
  if (name) {
36964
36986
  while (token() === 80 /* PrivateIdentifier */) {
@@ -36983,11 +37005,13 @@ var ts;
36983
37005
  && nextTokenJSDoc() === 59 /* AtToken */
36984
37006
  && ts.tokenIsIdentifierOrKeyword(nextTokenJSDoc())) {
36985
37007
  var kind = scanner.getTokenValue();
36986
- if (kind === "link" || kind === "linkcode" || kind === "linkplain") {
37008
+ if (isJSDocLinkTag(kind))
36987
37009
  return kind;
36988
- }
36989
37010
  }
36990
37011
  }
37012
+ function isJSDocLinkTag(kind) {
37013
+ return kind === "link" || kind === "linkcode" || kind === "linkplain";
37014
+ }
36991
37015
  function parseUnknownTag(start, tagName, indent, indentText) {
36992
37016
  return finishNode(factory.createJSDocUnknownTag(tagName, parseTrailingTagComments(start, getNodePos(), indent, indentText)), start);
36993
37017
  }
@@ -37093,7 +37117,7 @@ var ts;
37093
37117
  }
37094
37118
  function parseSeeTag(start, tagName, indent, indentText) {
37095
37119
  var isMarkdownOrJSDocLink = token() === 22 /* OpenBracketToken */
37096
- || lookAhead(function () { return nextTokenJSDoc() === 59 /* AtToken */ && ts.tokenIsIdentifierOrKeyword(nextTokenJSDoc()) && scanner.getTokenValue() === "link"; });
37120
+ || lookAhead(function () { return nextTokenJSDoc() === 59 /* AtToken */ && ts.tokenIsIdentifierOrKeyword(nextTokenJSDoc()) && isJSDocLinkTag(scanner.getTokenValue()); });
37097
37121
  var nameExpression = isMarkdownOrJSDocLink ? undefined : parseJSDocNameReference();
37098
37122
  var comments = indent !== undefined && indentText !== undefined ? parseTrailingTagComments(start, getNodePos(), indent, indentText) : undefined;
37099
37123
  return finishNode(factory.createJSDocSeeTag(tagName, nameExpression, comments), start);
@@ -37960,6 +37984,19 @@ var ts;
37960
37984
  return ts.fileExtensionIsOneOf(fileName, [".d.ts" /* Dts */, ".d.mts" /* Dmts */, ".d.cts" /* Dcts */]);
37961
37985
  }
37962
37986
  ts.isDeclarationFileName = isDeclarationFileName;
37987
+ function parseResolutionMode(mode, pos, end, reportDiagnostic) {
37988
+ if (!mode) {
37989
+ return undefined;
37990
+ }
37991
+ if (mode === "import") {
37992
+ return ts.ModuleKind.ESNext;
37993
+ }
37994
+ if (mode === "require") {
37995
+ return ts.ModuleKind.CommonJS;
37996
+ }
37997
+ reportDiagnostic(pos, end - pos, ts.Diagnostics.resolution_mode_should_be_either_require_or_import);
37998
+ return undefined;
37999
+ }
37963
38000
  /*@internal*/
37964
38001
  function processCommentPragmas(context, sourceText) {
37965
38002
  var pragmas = [];
@@ -38002,12 +38039,13 @@ var ts;
38002
38039
  var typeReferenceDirectives_1 = context.typeReferenceDirectives;
38003
38040
  var libReferenceDirectives_1 = context.libReferenceDirectives;
38004
38041
  ts.forEach(ts.toArray(entryOrList), function (arg) {
38005
- var _a = arg.arguments, types = _a.types, lib = _a.lib, path = _a.path;
38042
+ var _a = arg.arguments, types = _a.types, lib = _a.lib, path = _a.path, res = _a["resolution-mode"];
38006
38043
  if (arg.arguments["no-default-lib"]) {
38007
38044
  context.hasNoDefaultLib = true;
38008
38045
  }
38009
38046
  else if (types) {
38010
- typeReferenceDirectives_1.push({ pos: types.pos, end: types.end, fileName: types.value });
38047
+ var parsed = parseResolutionMode(res, types.pos, types.end, reportDiagnostic);
38048
+ typeReferenceDirectives_1.push(__assign({ pos: types.pos, end: types.end, fileName: types.value }, (parsed ? { resolutionMode: parsed } : {})));
38011
38049
  }
38012
38050
  else if (lib) {
38013
38051
  libReferenceDirectives_1.push({ pos: lib.pos, end: lib.end, fileName: lib.value });
@@ -41585,14 +41623,14 @@ var ts;
41585
41623
  * This is possible in case if resolution is performed for directives specified via 'types' parameter. In this case initial path for secondary lookups
41586
41624
  * is assumed to be the same as root directory of the project.
41587
41625
  */
41588
- function resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference, cache) {
41626
+ function resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference, cache, resolutionMode) {
41589
41627
  var traceEnabled = isTraceEnabled(options, host);
41590
41628
  if (redirectedReference) {
41591
41629
  options = redirectedReference.commandLine.options;
41592
41630
  }
41593
41631
  var containingDirectory = containingFile ? ts.getDirectoryPath(containingFile) : undefined;
41594
41632
  var perFolderCache = containingDirectory ? cache && cache.getOrCreateCacheForDirectory(containingDirectory, redirectedReference) : undefined;
41595
- var result = perFolderCache && perFolderCache.get(typeReferenceDirectiveName, /*mode*/ undefined);
41633
+ var result = perFolderCache && perFolderCache.get(typeReferenceDirectiveName, /*mode*/ resolutionMode);
41596
41634
  if (result) {
41597
41635
  if (traceEnabled) {
41598
41636
  trace(host, ts.Diagnostics.Resolving_type_reference_directive_0_containing_file_1, typeReferenceDirectiveName, containingFile);
@@ -41627,7 +41665,18 @@ var ts;
41627
41665
  }
41628
41666
  var failedLookupLocations = [];
41629
41667
  var features = getDefaultNodeResolutionFeatures(options);
41630
- var moduleResolutionState = { compilerOptions: options, host: host, traceEnabled: traceEnabled, failedLookupLocations: failedLookupLocations, packageJsonInfoCache: cache, features: features, conditions: ["node", "require", "types"] };
41668
+ // Unlike `import` statements, whose mode-calculating APIs are all guaranteed to return `undefined` if we're in an un-mode-ed module resolution
41669
+ // setting, type references will return their target mode regardless of options because of how the parser works, so we guard against the mode being
41670
+ // set in a non-modal module resolution setting here. Do note that our behavior is not particularly well defined when these mode-overriding imports
41671
+ // 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,
41672
+ // 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
41673
+ // resolution" should be (`node12`? `nodenext`?). As such, witnessing a mode-overriding triple-slash reference in a non-modal module resolution
41674
+ // context should _probably_ be an error - and that should likely be handled by the `Program` (which is what we do).
41675
+ if (resolutionMode === ts.ModuleKind.ESNext && (ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Node12 || ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext)) {
41676
+ features |= NodeResolutionFeatures.EsmMode;
41677
+ }
41678
+ var conditions = features & NodeResolutionFeatures.Exports ? features & NodeResolutionFeatures.EsmMode ? ["node", "import", "types"] : ["node", "require", "types"] : [];
41679
+ var moduleResolutionState = { compilerOptions: options, host: host, traceEnabled: traceEnabled, failedLookupLocations: failedLookupLocations, packageJsonInfoCache: cache, features: features, conditions: conditions };
41631
41680
  var resolved = primaryLookup();
41632
41681
  var primary = true;
41633
41682
  if (!resolved) {
@@ -41647,7 +41696,7 @@ var ts;
41647
41696
  };
41648
41697
  }
41649
41698
  result = { resolvedTypeReferenceDirective: resolvedTypeReferenceDirective, failedLookupLocations: failedLookupLocations };
41650
- perFolderCache === null || perFolderCache === void 0 ? void 0 : perFolderCache.set(typeReferenceDirectiveName, /*mode*/ undefined, result);
41699
+ perFolderCache === null || perFolderCache === void 0 ? void 0 : perFolderCache.set(typeReferenceDirectiveName, /*mode*/ resolutionMode, result);
41651
41700
  if (traceEnabled)
41652
41701
  traceResult(result);
41653
41702
  return result;
@@ -41933,7 +41982,11 @@ var ts;
41933
41982
  ts.Debug.assert(keys.length === values.length);
41934
41983
  var map = createModeAwareCache();
41935
41984
  for (var i = 0; i < keys.length; ++i) {
41936
- map.set(keys[i], ts.getModeForResolutionAtIndex(file, i), values[i]);
41985
+ var entry = keys[i];
41986
+ // We lower-case all type references because npm automatically lowercases all packages. See GH#9824.
41987
+ var name = !ts.isString(entry) ? entry.fileName.toLowerCase() : entry;
41988
+ var mode = !ts.isString(entry) ? entry.resolutionMode || file.impliedNodeFormat : ts.getModeForResolutionAtIndex(file, i);
41989
+ map.set(name, mode, values[i]);
41937
41990
  }
41938
41991
  return map;
41939
41992
  }
@@ -46953,8 +47006,7 @@ var ts;
46953
47006
  IntersectionState[IntersectionState["Source"] = 1] = "Source";
46954
47007
  IntersectionState[IntersectionState["Target"] = 2] = "Target";
46955
47008
  IntersectionState[IntersectionState["PropertyCheck"] = 4] = "PropertyCheck";
46956
- IntersectionState[IntersectionState["UnionIntersectionCheck"] = 8] = "UnionIntersectionCheck";
46957
- IntersectionState[IntersectionState["InPropertyCheck"] = 16] = "InPropertyCheck";
47009
+ IntersectionState[IntersectionState["InPropertyCheck"] = 8] = "InPropertyCheck";
46958
47010
  })(IntersectionState || (IntersectionState = {}));
46959
47011
  var RecursionFlags;
46960
47012
  (function (RecursionFlags) {
@@ -58675,13 +58727,15 @@ var ts;
58675
58727
  return signature;
58676
58728
  }
58677
58729
  function getOrCreateTypeFromSignature(signature) {
58730
+ var _a;
58678
58731
  // There are two ways to declare a construct signature, one is by declaring a class constructor
58679
58732
  // using the constructor keyword, and the other is declaring a bare construct signature in an
58680
58733
  // object type literal or interface (using the new keyword). Each way of declaring a constructor
58681
58734
  // will result in a different declaration kind.
58682
58735
  if (!signature.isolatedSignatureType) {
58683
- var kind = signature.declaration ? signature.declaration.kind : 0 /* Unknown */;
58684
- var isConstructor = kind === 170 /* Constructor */ || kind === 174 /* ConstructSignature */ || kind === 179 /* ConstructorType */;
58736
+ var kind = (_a = signature.declaration) === null || _a === void 0 ? void 0 : _a.kind;
58737
+ // If declaration is undefined, it is likely to be the signature of the default constructor.
58738
+ var isConstructor = kind === undefined || kind === 170 /* Constructor */ || kind === 174 /* ConstructSignature */ || kind === 179 /* ConstructorType */;
58685
58739
  var type = createObjectType(16 /* Anonymous */);
58686
58740
  type.members = emptySymbols;
58687
58741
  type.properties = ts.emptyArray;
@@ -59609,7 +59663,7 @@ var ts;
59609
59663
  }
59610
59664
  }
59611
59665
  var fixedLength = properties.length;
59612
- var lengthSymbol = createSymbol(4 /* Property */, "length");
59666
+ var lengthSymbol = createSymbol(4 /* Property */, "length", readonly ? 8 /* Readonly */ : 0);
59613
59667
  if (combinedFlags & 12 /* Variable */) {
59614
59668
  lengthSymbol.type = numberType;
59615
59669
  }
@@ -63249,11 +63303,11 @@ var ts;
63249
63303
  var overflow = false;
63250
63304
  var overrideNextErrorInfo = 0; // How many `reportRelationError` calls should be skipped in the elaboration pyramid
63251
63305
  var lastSkippedInfo;
63252
- var incompatibleStack = [];
63306
+ var incompatibleStack;
63253
63307
  var inPropertyCheck = false;
63254
63308
  ts.Debug.assert(relation !== identityRelation || !errorNode, "no error reporting in identity checking");
63255
63309
  var result = isRelatedTo(source, target, 3 /* Both */, /*reportErrors*/ !!errorNode, headMessage);
63256
- if (incompatibleStack.length) {
63310
+ if (incompatibleStack) {
63257
63311
  reportIncompatibleStack();
63258
63312
  }
63259
63313
  if (overflow) {
@@ -63310,19 +63364,19 @@ var ts;
63310
63364
  return {
63311
63365
  errorInfo: errorInfo,
63312
63366
  lastSkippedInfo: lastSkippedInfo,
63313
- incompatibleStack: incompatibleStack.slice(),
63367
+ incompatibleStack: incompatibleStack === null || incompatibleStack === void 0 ? void 0 : incompatibleStack.slice(),
63314
63368
  overrideNextErrorInfo: overrideNextErrorInfo,
63315
- relatedInfo: !relatedInfo ? undefined : relatedInfo.slice()
63369
+ relatedInfo: relatedInfo === null || relatedInfo === void 0 ? void 0 : relatedInfo.slice(),
63316
63370
  };
63317
63371
  }
63318
63372
  function reportIncompatibleError(message, arg0, arg1, arg2, arg3) {
63319
63373
  overrideNextErrorInfo++; // Suppress the next relation error
63320
63374
  lastSkippedInfo = undefined; // Reset skipped info cache
63321
- incompatibleStack.push([message, arg0, arg1, arg2, arg3]);
63375
+ (incompatibleStack || (incompatibleStack = [])).push([message, arg0, arg1, arg2, arg3]);
63322
63376
  }
63323
63377
  function reportIncompatibleStack() {
63324
- var stack = incompatibleStack;
63325
- incompatibleStack = [];
63378
+ var stack = incompatibleStack || [];
63379
+ incompatibleStack = undefined;
63326
63380
  var info = lastSkippedInfo;
63327
63381
  lastSkippedInfo = undefined;
63328
63382
  if (stack.length === 1) {
@@ -63428,7 +63482,7 @@ var ts;
63428
63482
  }
63429
63483
  function reportError(message, arg0, arg1, arg2, arg3) {
63430
63484
  ts.Debug.assert(!!errorNode);
63431
- if (incompatibleStack.length)
63485
+ if (incompatibleStack)
63432
63486
  reportIncompatibleStack();
63433
63487
  if (message.elidedInCompatabilityPyramid)
63434
63488
  return;
@@ -63444,7 +63498,7 @@ var ts;
63444
63498
  }
63445
63499
  }
63446
63500
  function reportRelationError(message, source, target) {
63447
- if (incompatibleStack.length)
63501
+ if (incompatibleStack)
63448
63502
  reportIncompatibleStack();
63449
63503
  var _a = getTypeNamesForErrorDisplay(source, target), sourceType = _a[0], targetType = _a[1];
63450
63504
  var generalizedSource = source;
@@ -63556,7 +63610,9 @@ var ts;
63556
63610
  if (isSimpleTypeRelatedTo(originalSource, originalTarget, relation, reportErrors ? reportError : undefined)) {
63557
63611
  return -1 /* True */;
63558
63612
  }
63559
- reportErrorResults(originalSource, originalTarget, 0 /* False */, !!(ts.getObjectFlags(originalSource) & 2048 /* JsxAttributes */));
63613
+ if (reportErrors) {
63614
+ reportErrorResults(originalSource, originalTarget, originalSource, originalTarget, headMessage);
63615
+ }
63560
63616
  return 0 /* False */;
63561
63617
  }
63562
63618
  // Normalize the source and target types: Turn fresh literal types into regular literal types,
@@ -63568,7 +63624,12 @@ var ts;
63568
63624
  if (source === target)
63569
63625
  return -1 /* True */;
63570
63626
  if (relation === identityRelation) {
63571
- return isIdenticalTo(source, target, recursionFlags);
63627
+ if (source.flags !== target.flags)
63628
+ return 0 /* False */;
63629
+ if (source.flags & 67358815 /* Singleton */)
63630
+ return -1 /* True */;
63631
+ traceUnionsOrIntersectionsTooLarge(source, target);
63632
+ return recursiveTypeRelatedTo(source, target, /*reportErrors*/ false, 0 /* None */, recursionFlags);
63572
63633
  }
63573
63634
  // We fastpath comparing a type parameter to exactly its constraint, as this is _super_ common,
63574
63635
  // and otherwise, for type parameters in large unions, causes us to need to compare the union to itself,
@@ -63578,163 +63639,130 @@ var ts;
63578
63639
  if (source.flags & 262144 /* TypeParameter */ && getConstraintOfType(source) === target) {
63579
63640
  return -1 /* True */;
63580
63641
  }
63581
- // Try to see if we're relating something like `Foo` -> `Bar | null | undefined`.
63582
- // If so, reporting the `null` and `undefined` in the type is hardly useful.
63583
- // First, see if we're even relating an object type to a union.
63584
- // Then see if the target is stripped down to a single non-union type.
63585
- // Note
63586
- // * We actually want to remove null and undefined naively here (rather than using getNonNullableType),
63587
- // since we don't want to end up with a worse error like "`Foo` is not assignable to `NonNullable<T>`"
63588
- // when dealing with generics.
63589
- // * We also don't deal with primitive source types, since we already halt elaboration below.
63590
- if (target.flags & 1048576 /* Union */ && source.flags & 524288 /* Object */ &&
63591
- target.types.length <= 3 && maybeTypeOfKind(target, 98304 /* Nullable */)) {
63592
- var nullStrippedTarget = extractTypesOfKind(target, ~98304 /* Nullable */);
63593
- if (!(nullStrippedTarget.flags & (1048576 /* Union */ | 131072 /* Never */))) {
63594
- target = getNormalizedType(nullStrippedTarget, /*writing*/ true);
63595
- }
63596
- if (source === nullStrippedTarget)
63597
- return -1 /* True */;
63642
+ // See if we're relating a definitely non-nullable type to a union that includes null and/or undefined
63643
+ // plus a single non-nullable type. If so, remove null and/or undefined from the target type.
63644
+ if (source.flags & 470302716 /* DefinitelyNonNullable */ && target.flags & 1048576 /* Union */) {
63645
+ var types = target.types;
63646
+ var candidate = types.length === 2 && types[0].flags & 98304 /* Nullable */ ? types[1] :
63647
+ types.length === 3 && types[0].flags & 98304 /* Nullable */ && types[1].flags & 98304 /* Nullable */ ? types[2] :
63648
+ undefined;
63649
+ if (candidate && !(candidate.flags & 98304 /* Nullable */)) {
63650
+ target = getNormalizedType(candidate, /*writing*/ true);
63651
+ if (source === target)
63652
+ return -1 /* True */;
63653
+ }
63598
63654
  }
63599
63655
  if (relation === comparableRelation && !(target.flags & 131072 /* Never */) && isSimpleTypeRelatedTo(target, source, relation) ||
63600
63656
  isSimpleTypeRelatedTo(source, target, relation, reportErrors ? reportError : undefined))
63601
63657
  return -1 /* True */;
63602
- var isComparingJsxAttributes = !!(ts.getObjectFlags(source) & 2048 /* JsxAttributes */);
63603
- var isPerformingExcessPropertyChecks = !(intersectionState & 2 /* Target */) && (isObjectLiteralType(source) && ts.getObjectFlags(source) & 16384 /* FreshLiteral */);
63604
- if (isPerformingExcessPropertyChecks) {
63605
- if (hasExcessProperties(source, target, reportErrors)) {
63658
+ if (source.flags & 469499904 /* StructuredOrInstantiable */ || target.flags & 469499904 /* StructuredOrInstantiable */) {
63659
+ var isPerformingExcessPropertyChecks = !(intersectionState & 2 /* Target */) && (isObjectLiteralType(source) && ts.getObjectFlags(source) & 16384 /* FreshLiteral */);
63660
+ if (isPerformingExcessPropertyChecks) {
63661
+ if (hasExcessProperties(source, target, reportErrors)) {
63662
+ if (reportErrors) {
63663
+ reportRelationError(headMessage, source, originalTarget.aliasSymbol ? originalTarget : target);
63664
+ }
63665
+ return 0 /* False */;
63666
+ }
63667
+ }
63668
+ var isPerformingCommonPropertyChecks = relation !== comparableRelation && !(intersectionState & 2 /* Target */) &&
63669
+ source.flags & (131068 /* Primitive */ | 524288 /* Object */ | 2097152 /* Intersection */) && source !== globalObjectType &&
63670
+ target.flags & (524288 /* Object */ | 2097152 /* Intersection */) && isWeakType(target) &&
63671
+ (getPropertiesOfType(source).length > 0 || typeHasCallOrConstructSignatures(source));
63672
+ var isComparingJsxAttributes = !!(ts.getObjectFlags(source) & 2048 /* JsxAttributes */);
63673
+ if (isPerformingCommonPropertyChecks && !hasCommonProperties(source, target, isComparingJsxAttributes)) {
63606
63674
  if (reportErrors) {
63607
- reportRelationError(headMessage, source, originalTarget.aliasSymbol ? originalTarget : target);
63675
+ var sourceString = typeToString(originalSource.aliasSymbol ? originalSource : source);
63676
+ var targetString = typeToString(originalTarget.aliasSymbol ? originalTarget : target);
63677
+ var calls = getSignaturesOfType(source, 0 /* Call */);
63678
+ var constructs = getSignaturesOfType(source, 1 /* Construct */);
63679
+ if (calls.length > 0 && isRelatedTo(getReturnTypeOfSignature(calls[0]), target, 1 /* Source */, /*reportErrors*/ false) ||
63680
+ constructs.length > 0 && isRelatedTo(getReturnTypeOfSignature(constructs[0]), target, 1 /* Source */, /*reportErrors*/ false)) {
63681
+ reportError(ts.Diagnostics.Value_of_type_0_has_no_properties_in_common_with_type_1_Did_you_mean_to_call_it, sourceString, targetString);
63682
+ }
63683
+ else {
63684
+ reportError(ts.Diagnostics.Type_0_has_no_properties_in_common_with_type_1, sourceString, targetString);
63685
+ }
63608
63686
  }
63609
63687
  return 0 /* False */;
63610
63688
  }
63611
- }
63612
- var isPerformingCommonPropertyChecks = relation !== comparableRelation && !(intersectionState & 2 /* Target */) &&
63613
- source.flags & (131068 /* Primitive */ | 524288 /* Object */ | 2097152 /* Intersection */) && source !== globalObjectType &&
63614
- target.flags & (524288 /* Object */ | 2097152 /* Intersection */) && isWeakType(target) &&
63615
- (getPropertiesOfType(source).length > 0 || typeHasCallOrConstructSignatures(source));
63616
- if (isPerformingCommonPropertyChecks && !hasCommonProperties(source, target, isComparingJsxAttributes)) {
63617
- if (reportErrors) {
63618
- var sourceString = typeToString(originalSource.aliasSymbol ? originalSource : source);
63619
- var targetString = typeToString(originalTarget.aliasSymbol ? originalTarget : target);
63620
- var calls = getSignaturesOfType(source, 0 /* Call */);
63621
- var constructs = getSignaturesOfType(source, 1 /* Construct */);
63622
- if (calls.length > 0 && isRelatedTo(getReturnTypeOfSignature(calls[0]), target, 1 /* Source */, /*reportErrors*/ false) ||
63623
- constructs.length > 0 && isRelatedTo(getReturnTypeOfSignature(constructs[0]), target, 1 /* Source */, /*reportErrors*/ false)) {
63624
- reportError(ts.Diagnostics.Value_of_type_0_has_no_properties_in_common_with_type_1_Did_you_mean_to_call_it, sourceString, targetString);
63625
- }
63626
- else {
63627
- reportError(ts.Diagnostics.Type_0_has_no_properties_in_common_with_type_1, sourceString, targetString);
63628
- }
63689
+ traceUnionsOrIntersectionsTooLarge(source, target);
63690
+ var skipCaching = source.flags & 1048576 /* Union */ && source.types.length < 4 && !(target.flags & 1048576 /* Union */) ||
63691
+ target.flags & 1048576 /* Union */ && target.types.length < 4 && !(source.flags & 469499904 /* StructuredOrInstantiable */);
63692
+ var result_7 = skipCaching ?
63693
+ unionOrIntersectionRelatedTo(source, target, reportErrors, intersectionState) :
63694
+ recursiveTypeRelatedTo(source, target, reportErrors, intersectionState, recursionFlags);
63695
+ // For certain combinations involving intersections and optional, excess, or mismatched properties we need
63696
+ // an extra property check where the intersection is viewed as a single object. The following are motivating
63697
+ // examples that all should be errors, but aren't without this extra property check:
63698
+ //
63699
+ // let obj: { a: { x: string } } & { c: number } = { a: { x: 'hello', y: 2 }, c: 5 }; // Nested excess property
63700
+ //
63701
+ // declare let wrong: { a: { y: string } };
63702
+ // let weak: { a?: { x?: number } } & { c?: string } = wrong; // Nested weak object type
63703
+ //
63704
+ // function foo<T extends object>(x: { a?: string }, y: T & { a: boolean }) {
63705
+ // x = y; // Mismatched property in source intersection
63706
+ // }
63707
+ //
63708
+ // We suppress recursive intersection property checks because they can generate lots of work when relating
63709
+ // recursive intersections that are structurally similar but not exactly identical. See #37854.
63710
+ if (result_7 && !inPropertyCheck && (target.flags & 2097152 /* Intersection */ && (isPerformingExcessPropertyChecks || isPerformingCommonPropertyChecks) ||
63711
+ 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 */); }))) {
63712
+ inPropertyCheck = true;
63713
+ result_7 &= recursiveTypeRelatedTo(source, target, reportErrors, 4 /* PropertyCheck */, recursionFlags);
63714
+ inPropertyCheck = false;
63715
+ }
63716
+ if (result_7) {
63717
+ return result_7;
63629
63718
  }
63630
- return 0 /* False */;
63631
- }
63632
- traceUnionsOrIntersectionsTooLarge(source, target);
63633
- var result = 0 /* False */;
63634
- var saveErrorInfo = captureErrorCalculationState();
63635
- if ((source.flags & 1048576 /* Union */ || target.flags & 1048576 /* Union */) && getConstituentCount(source) * getConstituentCount(target) < 4) {
63636
- // We skip caching when source or target is a union with no more than three constituents.
63637
- result = structuredTypeRelatedTo(source, target, reportErrors, intersectionState | 8 /* UnionIntersectionCheck */);
63638
63719
  }
63639
- else if (source.flags & 3145728 /* UnionOrIntersection */ || target.flags & 3145728 /* UnionOrIntersection */) {
63640
- result = recursiveTypeRelatedTo(source, target, reportErrors, intersectionState | 8 /* UnionIntersectionCheck */, recursionFlags);
63720
+ if (reportErrors) {
63721
+ reportErrorResults(originalSource, originalTarget, source, target, headMessage);
63641
63722
  }
63642
- if (!result && !(source.flags & 1048576 /* Union */) && (source.flags & (469499904 /* StructuredOrInstantiable */) || target.flags & 469499904 /* StructuredOrInstantiable */)) {
63643
- if (result = recursiveTypeRelatedTo(source, target, reportErrors, intersectionState, recursionFlags)) {
63644
- resetErrorInfo(saveErrorInfo);
63723
+ return 0 /* False */;
63724
+ }
63725
+ function reportErrorResults(originalSource, originalTarget, source, target, headMessage) {
63726
+ var sourceHasBase = !!getSingleBaseForNonAugmentingSubtype(originalSource);
63727
+ var targetHasBase = !!getSingleBaseForNonAugmentingSubtype(originalTarget);
63728
+ source = (originalSource.aliasSymbol || sourceHasBase) ? originalSource : source;
63729
+ target = (originalTarget.aliasSymbol || targetHasBase) ? originalTarget : target;
63730
+ var maybeSuppress = overrideNextErrorInfo > 0;
63731
+ if (maybeSuppress) {
63732
+ overrideNextErrorInfo--;
63733
+ }
63734
+ if (source.flags & 524288 /* Object */ && target.flags & 524288 /* Object */) {
63735
+ var currentError = errorInfo;
63736
+ tryElaborateArrayLikeErrors(source, target, /*reportErrors*/ true);
63737
+ if (errorInfo !== currentError) {
63738
+ maybeSuppress = !!errorInfo;
63739
+ }
63740
+ }
63741
+ if (source.flags & 524288 /* Object */ && target.flags & 131068 /* Primitive */) {
63742
+ tryElaborateErrorsForPrimitivesAndObjects(source, target);
63743
+ }
63744
+ else if (source.symbol && source.flags & 524288 /* Object */ && globalObjectType === source) {
63745
+ reportError(ts.Diagnostics.The_Object_type_is_assignable_to_very_few_other_types_Did_you_mean_to_use_the_any_type_instead);
63746
+ }
63747
+ else if (ts.getObjectFlags(source) & 2048 /* JsxAttributes */ && target.flags & 2097152 /* Intersection */) {
63748
+ var targetTypes = target.types;
63749
+ var intrinsicAttributes = getJsxType(JsxNames.IntrinsicAttributes, errorNode);
63750
+ var intrinsicClassAttributes = getJsxType(JsxNames.IntrinsicClassAttributes, errorNode);
63751
+ if (!isErrorType(intrinsicAttributes) && !isErrorType(intrinsicClassAttributes) &&
63752
+ (ts.contains(targetTypes, intrinsicAttributes) || ts.contains(targetTypes, intrinsicClassAttributes))) {
63753
+ // do not report top error
63754
+ return;
63645
63755
  }
63646
63756
  }
63647
- if (!result && source.flags & (2097152 /* Intersection */ | 262144 /* TypeParameter */)) {
63648
- // The combined constraint of an intersection type is the intersection of the constraints of
63649
- // the constituents. When an intersection type contains instantiable types with union type
63650
- // constraints, there are situations where we need to examine the combined constraint. One is
63651
- // when the target is a union type. Another is when the intersection contains types belonging
63652
- // to one of the disjoint domains. For example, given type variables T and U, each with the
63653
- // constraint 'string | number', the combined constraint of 'T & U' is 'string | number' and
63654
- // we need to check this constraint against a union on the target side. Also, given a type
63655
- // variable V constrained to 'string | number', 'V & number' has a combined constraint of
63656
- // 'string & number | number & number' which reduces to just 'number'.
63657
- // This also handles type parameters, as a type parameter with a union constraint compared against a union
63658
- // needs to have its constraint hoisted into an intersection with said type parameter, this way
63659
- // the type param can be compared with itself in the target (with the influence of its constraint to match other parts)
63660
- // For example, if `T extends 1 | 2` and `U extends 2 | 3` and we compare `T & U` to `T & U & (1 | 2 | 3)`
63661
- var constraint = getEffectiveConstraintOfIntersection(source.flags & 2097152 /* Intersection */ ? source.types : [source], !!(target.flags & 1048576 /* Union */));
63662
- if (constraint && (source.flags & 2097152 /* Intersection */ || target.flags & 1048576 /* Union */)) {
63663
- if (everyType(constraint, function (c) { return c !== source; })) { // Skip comparison if expansion contains the source itself
63664
- // TODO: Stack errors so we get a pyramid for the "normal" comparison above, _and_ a second for this
63665
- if (result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
63666
- resetErrorInfo(saveErrorInfo);
63667
- }
63668
- }
63669
- }
63757
+ else {
63758
+ errorInfo = elaborateNeverIntersection(errorInfo, originalTarget);
63670
63759
  }
63671
- // For certain combinations involving intersections and optional, excess, or mismatched properties we need
63672
- // an extra property check where the intersection is viewed as a single object. The following are motivating
63673
- // examples that all should be errors, but aren't without this extra property check:
63674
- //
63675
- // let obj: { a: { x: string } } & { c: number } = { a: { x: 'hello', y: 2 }, c: 5 }; // Nested excess property
63676
- //
63677
- // declare let wrong: { a: { y: string } };
63678
- // let weak: { a?: { x?: number } } & { c?: string } = wrong; // Nested weak object type
63679
- //
63680
- // function foo<T extends object>(x: { a?: string }, y: T & { a: boolean }) {
63681
- // x = y; // Mismatched property in source intersection
63682
- // }
63683
- //
63684
- // We suppress recursive intersection property checks because they can generate lots of work when relating
63685
- // recursive intersections that are structurally similar but not exactly identical. See #37854.
63686
- if (result && !inPropertyCheck && (target.flags & 2097152 /* Intersection */ && (isPerformingExcessPropertyChecks || isPerformingCommonPropertyChecks) ||
63687
- 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 */); }))) {
63688
- inPropertyCheck = true;
63689
- result &= recursiveTypeRelatedTo(source, target, reportErrors, 4 /* PropertyCheck */, recursionFlags);
63690
- inPropertyCheck = false;
63691
- }
63692
- reportErrorResults(source, target, result, isComparingJsxAttributes);
63693
- return result;
63694
- function reportErrorResults(source, target, result, isComparingJsxAttributes) {
63695
- if (!result && reportErrors) {
63696
- var sourceHasBase = !!getSingleBaseForNonAugmentingSubtype(originalSource);
63697
- var targetHasBase = !!getSingleBaseForNonAugmentingSubtype(originalTarget);
63698
- source = (originalSource.aliasSymbol || sourceHasBase) ? originalSource : source;
63699
- target = (originalTarget.aliasSymbol || targetHasBase) ? originalTarget : target;
63700
- var maybeSuppress = overrideNextErrorInfo > 0;
63701
- if (maybeSuppress) {
63702
- overrideNextErrorInfo--;
63703
- }
63704
- if (source.flags & 524288 /* Object */ && target.flags & 524288 /* Object */) {
63705
- var currentError = errorInfo;
63706
- tryElaborateArrayLikeErrors(source, target, reportErrors);
63707
- if (errorInfo !== currentError) {
63708
- maybeSuppress = !!errorInfo;
63709
- }
63710
- }
63711
- if (source.flags & 524288 /* Object */ && target.flags & 131068 /* Primitive */) {
63712
- tryElaborateErrorsForPrimitivesAndObjects(source, target);
63713
- }
63714
- else if (source.symbol && source.flags & 524288 /* Object */ && globalObjectType === source) {
63715
- reportError(ts.Diagnostics.The_Object_type_is_assignable_to_very_few_other_types_Did_you_mean_to_use_the_any_type_instead);
63716
- }
63717
- else if (isComparingJsxAttributes && target.flags & 2097152 /* Intersection */) {
63718
- var targetTypes = target.types;
63719
- var intrinsicAttributes = getJsxType(JsxNames.IntrinsicAttributes, errorNode);
63720
- var intrinsicClassAttributes = getJsxType(JsxNames.IntrinsicClassAttributes, errorNode);
63721
- if (!isErrorType(intrinsicAttributes) && !isErrorType(intrinsicClassAttributes) &&
63722
- (ts.contains(targetTypes, intrinsicAttributes) || ts.contains(targetTypes, intrinsicClassAttributes))) {
63723
- // do not report top error
63724
- return result;
63725
- }
63726
- }
63727
- else {
63728
- errorInfo = elaborateNeverIntersection(errorInfo, originalTarget);
63729
- }
63730
- if (!headMessage && maybeSuppress) {
63731
- lastSkippedInfo = [source, target];
63732
- // Used by, eg, missing property checking to replace the top-level message with a more informative one
63733
- return result;
63734
- }
63735
- reportRelationError(headMessage, source, target);
63736
- }
63760
+ if (!headMessage && maybeSuppress) {
63761
+ lastSkippedInfo = [source, target];
63762
+ // Used by, eg, missing property checking to replace the top-level message with a more informative one
63763
+ return;
63737
63764
  }
63765
+ reportRelationError(headMessage, source, target);
63738
63766
  }
63739
63767
  function traceUnionsOrIntersectionsTooLarge(source, target) {
63740
63768
  if (!ts.tracing) {
@@ -63761,21 +63789,6 @@ var ts;
63761
63789
  }
63762
63790
  }
63763
63791
  }
63764
- function isIdenticalTo(source, target, recursionFlags) {
63765
- if (source.flags !== target.flags)
63766
- return 0 /* False */;
63767
- if (source.flags & 67358815 /* Singleton */)
63768
- return -1 /* True */;
63769
- traceUnionsOrIntersectionsTooLarge(source, target);
63770
- if (source.flags & 3145728 /* UnionOrIntersection */) {
63771
- var result_7 = eachTypeRelatedToSomeType(source, target);
63772
- if (result_7) {
63773
- result_7 &= eachTypeRelatedToSomeType(target, source);
63774
- }
63775
- return result_7;
63776
- }
63777
- return recursiveTypeRelatedTo(source, target, /*reportErrors*/ false, 0 /* None */, recursionFlags);
63778
- }
63779
63792
  function getTypeOfPropertyInTypes(types, name) {
63780
63793
  var appendPropType = function (propTypes, type) {
63781
63794
  var _a;
@@ -63874,6 +63887,41 @@ var ts;
63874
63887
  function shouldCheckAsExcessProperty(prop, container) {
63875
63888
  return prop.valueDeclaration && container.valueDeclaration && prop.valueDeclaration.parent === container.valueDeclaration;
63876
63889
  }
63890
+ function unionOrIntersectionRelatedTo(source, target, reportErrors, intersectionState) {
63891
+ // Note that these checks are specifically ordered to produce correct results. In particular,
63892
+ // we need to deconstruct unions before intersections (because unions are always at the top),
63893
+ // and we need to handle "each" relations before "some" relations for the same kind of type.
63894
+ if (source.flags & 1048576 /* Union */) {
63895
+ return relation === comparableRelation ?
63896
+ someTypeRelatedToType(source, target, reportErrors && !(source.flags & 131068 /* Primitive */), intersectionState) :
63897
+ eachTypeRelatedToType(source, target, reportErrors && !(source.flags & 131068 /* Primitive */), intersectionState);
63898
+ }
63899
+ if (target.flags & 1048576 /* Union */) {
63900
+ return typeRelatedToSomeType(getRegularTypeOfObjectLiteral(source), target, reportErrors && !(source.flags & 131068 /* Primitive */) && !(target.flags & 131068 /* Primitive */));
63901
+ }
63902
+ if (target.flags & 2097152 /* Intersection */) {
63903
+ return typeRelatedToEachType(getRegularTypeOfObjectLiteral(source), target, reportErrors, 2 /* Target */);
63904
+ }
63905
+ // Source is an intersection. For the comparable relation, if the target is a primitive type we hoist the
63906
+ // constraints of all non-primitive types in the source into a new intersection. We do this because the
63907
+ // intersection may further constrain the constraints of the non-primitive types. For example, given a type
63908
+ // parameter 'T extends 1 | 2', the intersection 'T & 1' should be reduced to '1' such that it doesn't
63909
+ // appear to be comparable to '2'.
63910
+ if (relation === comparableRelation && target.flags & 131068 /* Primitive */) {
63911
+ var constraints = ts.sameMap(source.types, getBaseConstraintOrType);
63912
+ if (constraints !== source.types) {
63913
+ source = getIntersectionType(constraints);
63914
+ if (!(source.flags & 2097152 /* Intersection */)) {
63915
+ return isRelatedTo(source, target, 1 /* Source */, /*reportErrors*/ false);
63916
+ }
63917
+ }
63918
+ }
63919
+ // Check to see if any constituents of the intersection are immediately related to the target.
63920
+ // Don't report errors though. Elaborating on whether a source constituent is related to the target is
63921
+ // not actually useful and leads to some confusing error messages. Instead, we rely on the caller
63922
+ // checking whether the full intersection viewed as an object is related to the target.
63923
+ return someTypeRelatedToType(source, target, /*reportErrors*/ false, 1 /* Source */);
63924
+ }
63877
63925
  function eachTypeRelatedToSomeType(source, target) {
63878
63926
  var result = -1 /* True */;
63879
63927
  var sourceTypes = source.types;
@@ -63909,8 +63957,11 @@ var ts;
63909
63957
  }
63910
63958
  }
63911
63959
  if (reportErrors) {
63960
+ // Elaborate only if we can find a best matching type in the target union
63912
63961
  var bestMatchingType = getBestMatchingType(source, target, isRelatedTo);
63913
- isRelatedTo(source, bestMatchingType || targetTypes[targetTypes.length - 1], 2 /* Target */, /*reportErrors*/ true);
63962
+ if (bestMatchingType) {
63963
+ isRelatedTo(source, bestMatchingType, 2 /* Target */, /*reportErrors*/ true);
63964
+ }
63914
63965
  }
63915
63966
  return 0 /* False */;
63916
63967
  }
@@ -64046,7 +64097,7 @@ var ts;
64046
64097
  if (overflow) {
64047
64098
  return 0 /* False */;
64048
64099
  }
64049
- var keyIntersectionState = intersectionState | (inPropertyCheck ? 16 /* InPropertyCheck */ : 0);
64100
+ var keyIntersectionState = intersectionState | (inPropertyCheck ? 8 /* InPropertyCheck */ : 0);
64050
64101
  var id = getRelationKey(source, target, keyIntersectionState, relation, /*ingnoreConstraints*/ false);
64051
64102
  var entry = relation.get(id);
64052
64103
  if (entry !== undefined) {
@@ -64114,6 +64165,7 @@ var ts;
64114
64165
  return originalHandler(onlyUnreliable);
64115
64166
  };
64116
64167
  }
64168
+ var result;
64117
64169
  if (expandingFlags === 3 /* Both */) {
64118
64170
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.instant("checkTypes" /* CheckTypes */, "recursiveTypeRelatedTo_DepthLimit", {
64119
64171
  sourceId: source.id,
@@ -64123,8 +64175,13 @@ var ts;
64123
64175
  depth: sourceDepth,
64124
64176
  targetDepth: targetDepth
64125
64177
  });
64178
+ result = 3 /* Maybe */;
64179
+ }
64180
+ else {
64181
+ ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("checkTypes" /* CheckTypes */, "structuredTypeRelatedTo", { sourceId: source.id, targetId: target.id });
64182
+ result = structuredTypeRelatedTo(source, target, reportErrors, intersectionState);
64183
+ ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
64126
64184
  }
64127
- var result = expandingFlags !== 3 /* Both */ ? structuredTypeRelatedTo(source, target, reportErrors, intersectionState) : 3 /* Maybe */;
64128
64185
  if (outofbandVarianceMarkerHandler) {
64129
64186
  outofbandVarianceMarkerHandler = originalHandler;
64130
64187
  }
@@ -64156,98 +64213,97 @@ var ts;
64156
64213
  return result;
64157
64214
  }
64158
64215
  function structuredTypeRelatedTo(source, target, reportErrors, intersectionState) {
64159
- ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("checkTypes" /* CheckTypes */, "structuredTypeRelatedTo", { sourceId: source.id, targetId: target.id });
64160
- var result = structuredTypeRelatedToWorker(source, target, reportErrors, intersectionState);
64161
- ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
64162
- return result;
64163
- }
64164
- function structuredTypeRelatedToWorker(source, target, reportErrors, intersectionState) {
64165
64216
  if (intersectionState & 4 /* PropertyCheck */) {
64166
64217
  return propertiesRelatedTo(source, target, reportErrors, /*excludedProperties*/ undefined, 0 /* None */);
64167
64218
  }
64168
- if (intersectionState & 8 /* UnionIntersectionCheck */) {
64169
- // Note that these checks are specifically ordered to produce correct results. In particular,
64170
- // we need to deconstruct unions before intersections (because unions are always at the top),
64171
- // and we need to handle "each" relations before "some" relations for the same kind of type.
64172
- if (source.flags & 1048576 /* Union */) {
64173
- return relation === comparableRelation ?
64174
- someTypeRelatedToType(source, target, reportErrors && !(source.flags & 131068 /* Primitive */), intersectionState & ~8 /* UnionIntersectionCheck */) :
64175
- eachTypeRelatedToType(source, target, reportErrors && !(source.flags & 131068 /* Primitive */), intersectionState & ~8 /* UnionIntersectionCheck */);
64176
- }
64177
- if (target.flags & 1048576 /* Union */) {
64178
- return typeRelatedToSomeType(getRegularTypeOfObjectLiteral(source), target, reportErrors && !(source.flags & 131068 /* Primitive */) && !(target.flags & 131068 /* Primitive */));
64179
- }
64180
- if (target.flags & 2097152 /* Intersection */) {
64181
- return typeRelatedToEachType(getRegularTypeOfObjectLiteral(source), target, reportErrors, 2 /* Target */);
64182
- }
64183
- // Source is an intersection. For the comparable relation, if the target is a primitive type we hoist the
64184
- // constraints of all non-primitive types in the source into a new intersection. We do this because the
64185
- // intersection may further constrain the constraints of the non-primitive types. For example, given a type
64186
- // parameter 'T extends 1 | 2', the intersection 'T & 1' should be reduced to '1' such that it doesn't
64187
- // appear to be comparable to '2'.
64188
- if (relation === comparableRelation && target.flags & 131068 /* Primitive */) {
64189
- var constraints = ts.sameMap(source.types, getBaseConstraintOrType);
64190
- if (constraints !== source.types) {
64191
- source = getIntersectionType(constraints);
64192
- if (!(source.flags & 2097152 /* Intersection */)) {
64193
- return isRelatedTo(source, target, 1 /* Source */, /*reportErrors*/ false);
64194
- }
64219
+ var result;
64220
+ var originalErrorInfo;
64221
+ var varianceCheckFailed = false;
64222
+ var saveErrorInfo = captureErrorCalculationState();
64223
+ var sourceFlags = source.flags;
64224
+ var targetFlags = target.flags;
64225
+ if (relation === identityRelation) {
64226
+ // We've already checked that source.flags and target.flags are identical
64227
+ if (sourceFlags & 3145728 /* UnionOrIntersection */) {
64228
+ var result_8 = eachTypeRelatedToSomeType(source, target);
64229
+ if (result_8) {
64230
+ result_8 &= eachTypeRelatedToSomeType(target, source);
64195
64231
  }
64232
+ return result_8;
64196
64233
  }
64197
- // Check to see if any constituents of the intersection are immediately related to the target.
64198
- //
64199
- // Don't report errors though. Checking whether a constituent is related to the source is not actually
64200
- // useful and leads to some confusing error messages. Instead it is better to let the below checks
64201
- // take care of this, or to not elaborate at all. For instance,
64202
- //
64203
- // - For an object type (such as 'C = A & B'), users are usually more interested in structural errors.
64204
- //
64205
- // - For a union type (such as '(A | B) = (C & D)'), it's better to hold onto the whole intersection
64206
- // than to report that 'D' is not assignable to 'A' or 'B'.
64207
- //
64208
- // - For a primitive type or type parameter (such as 'number = A & B') there is no point in
64209
- // breaking the intersection apart.
64210
- return someTypeRelatedToType(source, target, /*reportErrors*/ false, 1 /* Source */);
64211
- }
64212
- var flags = source.flags & target.flags;
64213
- if (relation === identityRelation && !(flags & 524288 /* Object */)) {
64214
- if (flags & 4194304 /* Index */) {
64234
+ if (sourceFlags & 4194304 /* Index */) {
64215
64235
  return isRelatedTo(source.type, target.type, 3 /* Both */, /*reportErrors*/ false);
64216
64236
  }
64217
- var result_8 = 0 /* False */;
64218
- if (flags & 8388608 /* IndexedAccess */) {
64219
- if (result_8 = isRelatedTo(source.objectType, target.objectType, 3 /* Both */, /*reportErrors*/ false)) {
64220
- if (result_8 &= isRelatedTo(source.indexType, target.indexType, 3 /* Both */, /*reportErrors*/ false)) {
64221
- return result_8;
64237
+ if (sourceFlags & 8388608 /* IndexedAccess */) {
64238
+ if (result = isRelatedTo(source.objectType, target.objectType, 3 /* Both */, /*reportErrors*/ false)) {
64239
+ if (result &= isRelatedTo(source.indexType, target.indexType, 3 /* Both */, /*reportErrors*/ false)) {
64240
+ return result;
64222
64241
  }
64223
64242
  }
64224
64243
  }
64225
- if (flags & 16777216 /* Conditional */) {
64244
+ if (sourceFlags & 16777216 /* Conditional */) {
64226
64245
  if (source.root.isDistributive === target.root.isDistributive) {
64227
- if (result_8 = isRelatedTo(source.checkType, target.checkType, 3 /* Both */, /*reportErrors*/ false)) {
64228
- if (result_8 &= isRelatedTo(source.extendsType, target.extendsType, 3 /* Both */, /*reportErrors*/ false)) {
64229
- if (result_8 &= isRelatedTo(getTrueTypeFromConditionalType(source), getTrueTypeFromConditionalType(target), 3 /* Both */, /*reportErrors*/ false)) {
64230
- if (result_8 &= isRelatedTo(getFalseTypeFromConditionalType(source), getFalseTypeFromConditionalType(target), 3 /* Both */, /*reportErrors*/ false)) {
64231
- return result_8;
64246
+ if (result = isRelatedTo(source.checkType, target.checkType, 3 /* Both */, /*reportErrors*/ false)) {
64247
+ if (result &= isRelatedTo(source.extendsType, target.extendsType, 3 /* Both */, /*reportErrors*/ false)) {
64248
+ if (result &= isRelatedTo(getTrueTypeFromConditionalType(source), getTrueTypeFromConditionalType(target), 3 /* Both */, /*reportErrors*/ false)) {
64249
+ if (result &= isRelatedTo(getFalseTypeFromConditionalType(source), getFalseTypeFromConditionalType(target), 3 /* Both */, /*reportErrors*/ false)) {
64250
+ return result;
64232
64251
  }
64233
64252
  }
64234
64253
  }
64235
64254
  }
64236
64255
  }
64237
64256
  }
64238
- if (flags & 33554432 /* Substitution */) {
64257
+ if (sourceFlags & 33554432 /* Substitution */) {
64239
64258
  return isRelatedTo(source.substitute, target.substitute, 3 /* Both */, /*reportErrors*/ false);
64240
64259
  }
64241
- return 0 /* False */;
64260
+ if (!(sourceFlags & 524288 /* Object */)) {
64261
+ return 0 /* False */;
64262
+ }
64263
+ }
64264
+ else if (sourceFlags & 3145728 /* UnionOrIntersection */ || targetFlags & 3145728 /* UnionOrIntersection */) {
64265
+ if (result = unionOrIntersectionRelatedTo(source, target, reportErrors, intersectionState)) {
64266
+ return result;
64267
+ }
64268
+ if (source.flags & 2097152 /* Intersection */ || source.flags & 262144 /* TypeParameter */ && target.flags & 1048576 /* Union */) {
64269
+ // The combined constraint of an intersection type is the intersection of the constraints of
64270
+ // the constituents. When an intersection type contains instantiable types with union type
64271
+ // constraints, there are situations where we need to examine the combined constraint. One is
64272
+ // when the target is a union type. Another is when the intersection contains types belonging
64273
+ // to one of the disjoint domains. For example, given type variables T and U, each with the
64274
+ // constraint 'string | number', the combined constraint of 'T & U' is 'string | number' and
64275
+ // we need to check this constraint against a union on the target side. Also, given a type
64276
+ // variable V constrained to 'string | number', 'V & number' has a combined constraint of
64277
+ // 'string & number | number & number' which reduces to just 'number'.
64278
+ // This also handles type parameters, as a type parameter with a union constraint compared against a union
64279
+ // needs to have its constraint hoisted into an intersection with said type parameter, this way
64280
+ // the type param can be compared with itself in the target (with the influence of its constraint to match other parts)
64281
+ // For example, if `T extends 1 | 2` and `U extends 2 | 3` and we compare `T & U` to `T & U & (1 | 2 | 3)`
64282
+ var constraint = getEffectiveConstraintOfIntersection(source.flags & 2097152 /* Intersection */ ? source.types : [source], !!(target.flags & 1048576 /* Union */));
64283
+ if (constraint && everyType(constraint, function (c) { return c !== source; })) { // Skip comparison if expansion contains the source itself
64284
+ // TODO: Stack errors so we get a pyramid for the "normal" comparison above, _and_ a second for this
64285
+ if (result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
64286
+ resetErrorInfo(saveErrorInfo);
64287
+ return result;
64288
+ }
64289
+ }
64290
+ }
64291
+ // The ordered decomposition above doesn't handle all cases. Specifically, we also need to handle:
64292
+ // Source is instantiable (e.g. source has union or intersection constraint).
64293
+ // Source is an object, target is a union (e.g. { a, b: boolean } <=> { a, b: true } | { a, b: false }).
64294
+ // Source is an intersection, target is an object (e.g. { a } & { b } <=> { a, b }).
64295
+ // Source is an intersection, target is a union (e.g. { a } & { b: boolean } <=> { a, b: true } | { a, b: false }).
64296
+ // Source is an intersection, target instantiable (e.g. string & { tag } <=> T["a"] constrained to string & { tag }).
64297
+ if (!(sourceFlags & 465829888 /* Instantiable */ ||
64298
+ sourceFlags & 524288 /* Object */ && targetFlags & 1048576 /* Union */ ||
64299
+ sourceFlags & 2097152 /* Intersection */ && targetFlags & (524288 /* Object */ | 1048576 /* Union */ | 465829888 /* Instantiable */))) {
64300
+ return 0 /* False */;
64301
+ }
64242
64302
  }
64243
- var result;
64244
- var originalErrorInfo;
64245
- var varianceCheckFailed = false;
64246
- var saveErrorInfo = captureErrorCalculationState();
64247
64303
  // We limit alias variance probing to only object and conditional types since their alias behavior
64248
64304
  // is more predictable than other, interned types, which may or may not have an alias depending on
64249
64305
  // the order in which things were checked.
64250
- if (source.flags & (524288 /* Object */ | 16777216 /* Conditional */) && source.aliasSymbol &&
64306
+ if (sourceFlags & (524288 /* Object */ | 16777216 /* Conditional */) && source.aliasSymbol &&
64251
64307
  source.aliasTypeArguments && source.aliasSymbol === target.aliasSymbol &&
64252
64308
  !(source.aliasTypeArgumentsContainsMarker || target.aliasTypeArgumentsContainsMarker)) {
64253
64309
  var variances = getAliasVariances(source.aliasSymbol);
@@ -64265,7 +64321,7 @@ var ts;
64265
64321
  isSingleElementGenericTupleType(target) && (target.target.readonly || isMutableArrayOrTuple(getBaseConstraintOfType(source) || source)) && (result = isRelatedTo(source, getTypeArguments(target)[0], 2 /* Target */))) {
64266
64322
  return result;
64267
64323
  }
64268
- if (target.flags & 262144 /* TypeParameter */) {
64324
+ if (targetFlags & 262144 /* TypeParameter */) {
64269
64325
  // 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].
64270
64326
  if (ts.getObjectFlags(source) & 32 /* Mapped */ && !source.declaration.nameType && isRelatedTo(getIndexType(target), getConstraintTypeFromMappedType(source), 3 /* Both */)) {
64271
64327
  if (!(getMappedTypeModifiers(source) & 4 /* IncludeOptional */)) {
@@ -64277,10 +64333,10 @@ var ts;
64277
64333
  }
64278
64334
  }
64279
64335
  }
64280
- else if (target.flags & 4194304 /* Index */) {
64336
+ else if (targetFlags & 4194304 /* Index */) {
64281
64337
  var targetType_1 = target.type;
64282
64338
  // A keyof S is related to a keyof T if T is related to S.
64283
- if (source.flags & 4194304 /* Index */) {
64339
+ if (sourceFlags & 4194304 /* Index */) {
64284
64340
  if (result = isRelatedTo(targetType_1, source.type, 3 /* Both */, /*reportErrors*/ false)) {
64285
64341
  return result;
64286
64342
  }
@@ -64331,8 +64387,8 @@ var ts;
64331
64387
  }
64332
64388
  }
64333
64389
  }
64334
- else if (target.flags & 8388608 /* IndexedAccess */) {
64335
- if (source.flags & 8388608 /* IndexedAccess */) {
64390
+ else if (targetFlags & 8388608 /* IndexedAccess */) {
64391
+ if (sourceFlags & 8388608 /* IndexedAccess */) {
64336
64392
  // Relate components directly before falling back to constraint relationships
64337
64393
  // A type S[K] is related to a type T[J] if S is related to T and K is related to J.
64338
64394
  if (result = isRelatedTo(source.objectType, target.objectType, 3 /* Both */, reportErrors)) {
@@ -64438,7 +64494,7 @@ var ts;
64438
64494
  }
64439
64495
  }
64440
64496
  }
64441
- else if (target.flags & 16777216 /* Conditional */) {
64497
+ else if (targetFlags & 16777216 /* Conditional */) {
64442
64498
  // If we reach 10 levels of nesting for the same conditional type, assume it is an infinitely expanding recursive
64443
64499
  // conditional type and bail out with a Ternary.Maybe result.
64444
64500
  if (isDeeplyNestedType(target, targetStack, targetDepth, 10)) {
@@ -64463,8 +64519,8 @@ var ts;
64463
64519
  }
64464
64520
  }
64465
64521
  }
64466
- else if (target.flags & 134217728 /* TemplateLiteral */) {
64467
- if (source.flags & 134217728 /* TemplateLiteral */) {
64522
+ else if (targetFlags & 134217728 /* TemplateLiteral */) {
64523
+ if (sourceFlags & 134217728 /* TemplateLiteral */) {
64468
64524
  if (relation === comparableRelation) {
64469
64525
  return templateLiteralTypesDefinitelyUnrelated(source, target) ? 0 /* False */ : -1 /* True */;
64470
64526
  }
@@ -64476,11 +64532,11 @@ var ts;
64476
64532
  return -1 /* True */;
64477
64533
  }
64478
64534
  }
64479
- if (source.flags & 8650752 /* TypeVariable */) {
64480
- // IndexedAccess comparisons are handled above in the `target.flags & TypeFlage.IndexedAccess` branch
64481
- if (!(source.flags & 8388608 /* IndexedAccess */ && target.flags & 8388608 /* IndexedAccess */)) {
64535
+ if (sourceFlags & 8650752 /* TypeVariable */) {
64536
+ // IndexedAccess comparisons are handled above in the `targetFlags & TypeFlage.IndexedAccess` branch
64537
+ if (!(sourceFlags & 8388608 /* IndexedAccess */ && targetFlags & 8388608 /* IndexedAccess */)) {
64482
64538
  var constraint = getConstraintOfType(source);
64483
- if (!constraint || (source.flags & 262144 /* TypeParameter */ && constraint.flags & 1 /* Any */)) {
64539
+ if (!constraint || (sourceFlags & 262144 /* TypeParameter */ && constraint.flags & 1 /* Any */)) {
64484
64540
  // A type variable with no constraint is not related to the non-primitive object type.
64485
64541
  if (result = isRelatedTo(emptyObjectType, extractTypesOfKind(target, ~67108864 /* NonPrimitive */), 3 /* Both */)) {
64486
64542
  resetErrorInfo(saveErrorInfo);
@@ -64493,7 +64549,7 @@ var ts;
64493
64549
  return result;
64494
64550
  }
64495
64551
  // slower, fuller, this-instantiated check (necessary when comparing raw `this` types from base classes), see `subclassWithPolymorphicThisIsAssignable.ts` test for example
64496
- else if (result = isRelatedTo(getTypeWithThisArgument(constraint, source), target, 1 /* Source */, reportErrors && !(target.flags & source.flags & 262144 /* TypeParameter */), /*headMessage*/ undefined, intersectionState)) {
64552
+ else if (result = isRelatedTo(getTypeWithThisArgument(constraint, source), target, 1 /* Source */, reportErrors && !(targetFlags & sourceFlags & 262144 /* TypeParameter */), /*headMessage*/ undefined, intersectionState)) {
64497
64553
  resetErrorInfo(saveErrorInfo);
64498
64554
  return result;
64499
64555
  }
@@ -64510,14 +64566,14 @@ var ts;
64510
64566
  }
64511
64567
  }
64512
64568
  }
64513
- else if (source.flags & 4194304 /* Index */) {
64569
+ else if (sourceFlags & 4194304 /* Index */) {
64514
64570
  if (result = isRelatedTo(keyofConstraintType, target, 1 /* Source */, reportErrors)) {
64515
64571
  resetErrorInfo(saveErrorInfo);
64516
64572
  return result;
64517
64573
  }
64518
64574
  }
64519
- else if (source.flags & 134217728 /* TemplateLiteral */ && !(target.flags & 524288 /* Object */)) {
64520
- if (!(target.flags & 134217728 /* TemplateLiteral */)) {
64575
+ else if (sourceFlags & 134217728 /* TemplateLiteral */ && !(targetFlags & 524288 /* Object */)) {
64576
+ if (!(targetFlags & 134217728 /* TemplateLiteral */)) {
64521
64577
  var constraint = getBaseConstraintOfType(source);
64522
64578
  if (constraint && constraint !== source && (result = isRelatedTo(constraint, target, 1 /* Source */, reportErrors))) {
64523
64579
  resetErrorInfo(saveErrorInfo);
@@ -64525,8 +64581,8 @@ var ts;
64525
64581
  }
64526
64582
  }
64527
64583
  }
64528
- else if (source.flags & 268435456 /* StringMapping */) {
64529
- if (target.flags & 268435456 /* StringMapping */ && source.symbol === target.symbol) {
64584
+ else if (sourceFlags & 268435456 /* StringMapping */) {
64585
+ if (targetFlags & 268435456 /* StringMapping */ && source.symbol === target.symbol) {
64530
64586
  if (result = isRelatedTo(source.type, target.type, 3 /* Both */, reportErrors)) {
64531
64587
  resetErrorInfo(saveErrorInfo);
64532
64588
  return result;
@@ -64540,14 +64596,14 @@ var ts;
64540
64596
  }
64541
64597
  }
64542
64598
  }
64543
- else if (source.flags & 16777216 /* Conditional */) {
64599
+ else if (sourceFlags & 16777216 /* Conditional */) {
64544
64600
  // If we reach 10 levels of nesting for the same conditional type, assume it is an infinitely expanding recursive
64545
64601
  // conditional type and bail out with a Ternary.Maybe result.
64546
64602
  if (isDeeplyNestedType(source, sourceStack, sourceDepth, 10)) {
64547
64603
  resetErrorInfo(saveErrorInfo);
64548
64604
  return 3 /* Maybe */;
64549
64605
  }
64550
- if (target.flags & 16777216 /* Conditional */) {
64606
+ if (targetFlags & 16777216 /* Conditional */) {
64551
64607
  // Two conditional types 'T1 extends U1 ? X1 : Y1' and 'T2 extends U2 ? X2 : Y2' are related if
64552
64608
  // one of T1 and T2 is related to the other, U1 and U2 are identical types, X1 is related to X2,
64553
64609
  // and Y1 is related to Y2.
@@ -64607,9 +64663,10 @@ var ts;
64607
64663
  }
64608
64664
  return 0 /* False */;
64609
64665
  }
64610
- var sourceIsPrimitive = !!(source.flags & 131068 /* Primitive */);
64666
+ var sourceIsPrimitive = !!(sourceFlags & 131068 /* Primitive */);
64611
64667
  if (relation !== identityRelation) {
64612
64668
  source = getApparentType(source);
64669
+ sourceFlags = source.flags;
64613
64670
  }
64614
64671
  else if (isGenericMappedType(source)) {
64615
64672
  return 0 /* False */;
@@ -64656,7 +64713,7 @@ var ts;
64656
64713
  // In a check of the form X = A & B, we will have previously checked if A relates to X or B relates
64657
64714
  // to X. Failing both of those we want to check if the aggregation of A and B's members structurally
64658
64715
  // relates to X. Thus, we include intersection types on the source side here.
64659
- if (source.flags & (524288 /* Object */ | 2097152 /* Intersection */) && target.flags & 524288 /* Object */) {
64716
+ if (sourceFlags & (524288 /* Object */ | 2097152 /* Intersection */) && targetFlags & 524288 /* Object */) {
64660
64717
  // Report structural errors only if we haven't reported any errors yet
64661
64718
  var reportStructuralErrors = reportErrors && errorInfo === saveErrorInfo.errorInfo && !sourceIsPrimitive;
64662
64719
  result = propertiesRelatedTo(source, target, reportStructuralErrors, /*excludedProperties*/ undefined, intersectionState);
@@ -64680,7 +64737,7 @@ var ts;
64680
64737
  // there exists a constituent of T for every combination of the discriminants of S
64681
64738
  // with respect to T. We do not report errors here, as we will use the existing
64682
64739
  // error result from checking each constituent of the union.
64683
- if (source.flags & (524288 /* Object */ | 2097152 /* Intersection */) && target.flags & 1048576 /* Union */) {
64740
+ if (sourceFlags & (524288 /* Object */ | 2097152 /* Intersection */) && targetFlags & 1048576 /* Union */) {
64684
64741
  var objectOnlyTarget = extractTypesOfKind(target, 524288 /* Object */ | 2097152 /* Intersection */ | 33554432 /* Substitution */);
64685
64742
  if (objectOnlyTarget.flags & 1048576 /* Union */) {
64686
64743
  var result_9 = typeRelatedToDiscriminatedType(source, objectOnlyTarget);
@@ -65204,7 +65261,6 @@ var ts;
65204
65261
  }
65205
65262
  }
65206
65263
  var result = -1 /* True */;
65207
- var saveErrorInfo = captureErrorCalculationState();
65208
65264
  var incompatibleReporter = kind === 1 /* Construct */ ? reportIncompatibleConstructSignatureReturn : reportIncompatibleCallSignatureReturn;
65209
65265
  var sourceObjectFlags = ts.getObjectFlags(source);
65210
65266
  var targetObjectFlags = ts.getObjectFlags(target);
@@ -65245,6 +65301,7 @@ var ts;
65245
65301
  else {
65246
65302
  outer: for (var _i = 0, targetSignatures_1 = targetSignatures; _i < targetSignatures_1.length; _i++) {
65247
65303
  var t = targetSignatures_1[_i];
65304
+ var saveErrorInfo = captureErrorCalculationState();
65248
65305
  // Only elaborate errors from the first failure
65249
65306
  var shouldElaborateErrors = reportErrors;
65250
65307
  for (var _c = 0, sourceSignatures_1 = sourceSignatures; _c < sourceSignatures_1.length; _c++) {
@@ -68415,9 +68472,6 @@ var ts;
68415
68472
  getUnionType(ts.map(type.types, mapper), 1 /* Literal */, aliasSymbol, aliasTypeArguments) :
68416
68473
  mapType(type, mapper);
68417
68474
  }
68418
- function getConstituentCount(type) {
68419
- return type.flags & 1048576 /* Union */ ? type.types.length : 1;
68420
- }
68421
68475
  function extractTypesOfKind(type, kind) {
68422
68476
  return filterType(type, function (t) { return (t.flags & kind) !== 0; });
68423
68477
  }
@@ -73138,6 +73192,9 @@ var ts;
73138
73192
  if (compilerOptions.noPropertyAccessFromIndexSignature && ts.isPropertyAccessExpression(node)) {
73139
73193
  error(right, ts.Diagnostics.Property_0_comes_from_an_index_signature_so_it_must_be_accessed_with_0, ts.unescapeLeadingUnderscores(right.escapedText));
73140
73194
  }
73195
+ if (indexInfo.declaration && ts.getCombinedNodeFlags(indexInfo.declaration) & 134217728 /* Deprecated */) {
73196
+ addDeprecatedSuggestion(right, [indexInfo.declaration], right.escapedText);
73197
+ }
73141
73198
  }
73142
73199
  else {
73143
73200
  if (isDeprecatedSymbol(prop) && isUncalledFunctionReference(node, prop) && prop.declarations) {
@@ -76083,21 +76140,22 @@ var ts;
76083
76140
  if (links.type === unknownType) {
76084
76141
  links.type = getTypeFromBindingPattern(declaration.name);
76085
76142
  }
76086
- assignBindingElementTypes(declaration.name);
76143
+ assignBindingElementTypes(declaration.name, links.type);
76087
76144
  }
76088
76145
  }
76089
76146
  }
76090
76147
  // When contextual typing assigns a type to a parameter that contains a binding pattern, we also need to push
76091
76148
  // the destructured type into the contained binding elements.
76092
- function assignBindingElementTypes(pattern) {
76149
+ function assignBindingElementTypes(pattern, parentType) {
76093
76150
  for (var _i = 0, _a = pattern.elements; _i < _a.length; _i++) {
76094
76151
  var element = _a[_i];
76095
76152
  if (!ts.isOmittedExpression(element)) {
76153
+ var type = getBindingElementTypeFromParentType(element, parentType);
76096
76154
  if (element.name.kind === 79 /* Identifier */) {
76097
- getSymbolLinks(getSymbolOfNode(element)).type = getTypeForBindingElement(element);
76155
+ getSymbolLinks(getSymbolOfNode(element)).type = type;
76098
76156
  }
76099
76157
  else {
76100
- assignBindingElementTypes(element.name);
76158
+ assignBindingElementTypes(element.name, type);
76101
76159
  }
76102
76160
  }
76103
76161
  }
@@ -79838,28 +79896,24 @@ var ts;
79838
79896
  if (returnType.flags & 1 /* Any */) {
79839
79897
  return;
79840
79898
  }
79899
+ var headMessage;
79841
79900
  var expectedReturnType;
79842
- var headMessage = getDiagnosticHeadMessageForDecoratorResolution(node);
79843
- var errorInfo;
79844
79901
  switch (node.parent.kind) {
79845
79902
  case 256 /* ClassDeclaration */:
79903
+ headMessage = ts.Diagnostics.Decorator_function_return_type_0_is_not_assignable_to_type_1;
79846
79904
  var classSymbol = getSymbolOfNode(node.parent);
79847
79905
  var classConstructorType = getTypeOfSymbol(classSymbol);
79848
79906
  expectedReturnType = getUnionType([classConstructorType, voidType]);
79849
79907
  break;
79850
- case 163 /* Parameter */:
79851
- expectedReturnType = voidType;
79852
- errorInfo = ts.chainDiagnosticMessages(
79853
- /*details*/ undefined, ts.Diagnostics.The_return_type_of_a_parameter_decorator_function_must_be_either_void_or_any);
79854
- break;
79855
79908
  case 166 /* PropertyDeclaration */:
79909
+ case 163 /* Parameter */:
79910
+ headMessage = ts.Diagnostics.Decorator_function_return_type_is_0_but_is_expected_to_be_void_or_any;
79856
79911
  expectedReturnType = voidType;
79857
- errorInfo = ts.chainDiagnosticMessages(
79858
- /*details*/ undefined, ts.Diagnostics.The_return_type_of_a_property_decorator_function_must_be_either_void_or_any);
79859
79912
  break;
79860
79913
  case 168 /* MethodDeclaration */:
79861
79914
  case 171 /* GetAccessor */:
79862
79915
  case 172 /* SetAccessor */:
79916
+ headMessage = ts.Diagnostics.Decorator_function_return_type_0_is_not_assignable_to_type_1;
79863
79917
  var methodType = getTypeOfNode(node.parent);
79864
79918
  var descriptorType = createTypedPropertyDescriptorType(methodType);
79865
79919
  expectedReturnType = getUnionType([descriptorType, voidType]);
@@ -79867,7 +79921,7 @@ var ts;
79867
79921
  default:
79868
79922
  return ts.Debug.fail();
79869
79923
  }
79870
- checkTypeAssignableTo(returnType, expectedReturnType, node, headMessage, function () { return errorInfo; });
79924
+ checkTypeAssignableTo(returnType, expectedReturnType, node, headMessage);
79871
79925
  }
79872
79926
  /**
79873
79927
  * If a TypeNode can be resolved to a value symbol imported from an external module, it is
@@ -85415,7 +85469,7 @@ var ts;
85415
85469
  if (resolvedTypeReferenceDirectives) {
85416
85470
  // populate reverse mapping: file path -> type reference directive that was resolved to this file
85417
85471
  fileToDirective = new ts.Map();
85418
- resolvedTypeReferenceDirectives.forEach(function (resolvedDirective, key) {
85472
+ resolvedTypeReferenceDirectives.forEach(function (resolvedDirective, key, mode) {
85419
85473
  if (!resolvedDirective || !resolvedDirective.resolvedFileName) {
85420
85474
  return;
85421
85475
  }
@@ -85423,7 +85477,7 @@ var ts;
85423
85477
  if (file) {
85424
85478
  // Add the transitive closure of path references loaded by this file (as long as they are not)
85425
85479
  // part of an existing type reference.
85426
- addReferencedFilesToTypeDirective(file, key);
85480
+ addReferencedFilesToTypeDirective(file, key, mode);
85427
85481
  }
85428
85482
  });
85429
85483
  }
@@ -85617,16 +85671,16 @@ var ts;
85617
85671
  }
85618
85672
  return false;
85619
85673
  }
85620
- function addReferencedFilesToTypeDirective(file, key) {
85674
+ function addReferencedFilesToTypeDirective(file, key, mode) {
85621
85675
  if (fileToDirective.has(file.path))
85622
85676
  return;
85623
- fileToDirective.set(file.path, key);
85677
+ fileToDirective.set(file.path, [key, mode]);
85624
85678
  for (var _i = 0, _a = file.referencedFiles; _i < _a.length; _i++) {
85625
- var fileName = _a[_i].fileName;
85679
+ var _b = _a[_i], fileName = _b.fileName, resolutionMode = _b.resolutionMode;
85626
85680
  var resolvedFile = ts.resolveTripleslashReference(fileName, file.fileName);
85627
85681
  var referencedFile = host.getSourceFile(resolvedFile);
85628
85682
  if (referencedFile) {
85629
- addReferencedFilesToTypeDirective(referencedFile, key);
85683
+ addReferencedFilesToTypeDirective(referencedFile, key, resolutionMode || file.impliedNodeFormat);
85630
85684
  }
85631
85685
  }
85632
85686
  }
@@ -87331,28 +87385,27 @@ var ts;
87331
87385
  }
87332
87386
  function findMostOverlappyType(source, unionTarget) {
87333
87387
  var bestMatch;
87334
- var matchingCount = 0;
87335
- for (var _i = 0, _a = unionTarget.types; _i < _a.length; _i++) {
87336
- var target = _a[_i];
87337
- var overlap = getIntersectionType([getIndexType(source), getIndexType(target)]);
87338
- if (overlap.flags & 4194304 /* Index */) {
87339
- // perfect overlap of keys
87340
- bestMatch = target;
87341
- matchingCount = Infinity;
87342
- }
87343
- else if (overlap.flags & 1048576 /* Union */) {
87344
- // We only want to account for literal types otherwise.
87345
- // If we have a union of index types, it seems likely that we
87346
- // needed to elaborate between two generic mapped types anyway.
87347
- var len = ts.length(ts.filter(overlap.types, isUnitType));
87348
- if (len >= matchingCount) {
87349
- bestMatch = target;
87350
- matchingCount = len;
87351
- }
87352
- }
87353
- else if (isUnitType(overlap) && 1 >= matchingCount) {
87354
- bestMatch = target;
87355
- matchingCount = 1;
87388
+ if (!(source.flags & (131068 /* Primitive */ | 406847488 /* InstantiablePrimitive */))) {
87389
+ var matchingCount = 0;
87390
+ for (var _i = 0, _a = unionTarget.types; _i < _a.length; _i++) {
87391
+ var target = _a[_i];
87392
+ if (!(target.flags & (131068 /* Primitive */ | 406847488 /* InstantiablePrimitive */))) {
87393
+ var overlap = getIntersectionType([getIndexType(source), getIndexType(target)]);
87394
+ if (overlap.flags & 4194304 /* Index */) {
87395
+ // perfect overlap of keys
87396
+ return target;
87397
+ }
87398
+ else if (isUnitType(overlap) || overlap.flags & 1048576 /* Union */) {
87399
+ // We only want to account for literal types otherwise.
87400
+ // If we have a union of index types, it seems likely that we
87401
+ // needed to elaborate between two generic mapped types anyway.
87402
+ var len = overlap.flags & 1048576 /* Union */ ? ts.countWhere(overlap.types, isUnitType) : 1;
87403
+ if (len >= matchingCount) {
87404
+ bestMatch = target;
87405
+ matchingCount = len;
87406
+ }
87407
+ }
87408
+ }
87356
87409
  }
87357
87410
  }
87358
87411
  return bestMatch;
@@ -106395,7 +106448,7 @@ var ts;
106395
106448
  var sourceFile = ts.createUnparsedSourceFile(prepend, "dts", stripInternal);
106396
106449
  hasNoDefaultLib_1 = hasNoDefaultLib_1 || !!sourceFile.hasNoDefaultLib;
106397
106450
  collectReferences(sourceFile, refs);
106398
- recordTypeReferenceDirectivesIfNecessary(sourceFile.typeReferenceDirectives);
106451
+ recordTypeReferenceDirectivesIfNecessary(ts.map(sourceFile.typeReferenceDirectives, function (ref) { return [ref.fileName, ref.resolutionMode]; }));
106399
106452
  collectLibs(sourceFile, libs);
106400
106453
  return sourceFile;
106401
106454
  }
@@ -106450,9 +106503,10 @@ var ts;
106450
106503
  return ts.map(ts.arrayFrom(libs.keys()), function (lib) { return ({ fileName: lib, pos: -1, end: -1 }); });
106451
106504
  }
106452
106505
  function getFileReferencesForUsedTypeReferences() {
106453
- return necessaryTypeReferences ? ts.mapDefined(ts.arrayFrom(necessaryTypeReferences.keys()), getFileReferenceForTypeName) : [];
106506
+ return necessaryTypeReferences ? ts.mapDefined(ts.arrayFrom(necessaryTypeReferences.keys()), getFileReferenceForSpecifierModeTuple) : [];
106454
106507
  }
106455
- function getFileReferenceForTypeName(typeName) {
106508
+ function getFileReferenceForSpecifierModeTuple(_a) {
106509
+ var typeName = _a[0], mode = _a[1];
106456
106510
  // Elide type references for which we have imports
106457
106511
  if (emittedImports) {
106458
106512
  for (var _i = 0, emittedImports_1 = emittedImports; _i < emittedImports_1.length; _i++) {
@@ -106468,7 +106522,7 @@ var ts;
106468
106522
  }
106469
106523
  }
106470
106524
  }
106471
- return { fileName: typeName, pos: -1, end: -1 };
106525
+ return __assign({ fileName: typeName, pos: -1, end: -1 }, (mode ? { resolutionMode: mode } : undefined));
106472
106526
  }
106473
106527
  function mapReferencesIntoArray(references, outputFilePath) {
106474
106528
  return function (file) {
@@ -106488,7 +106542,7 @@ var ts;
106488
106542
  // If some compiler option/symlink/whatever allows access to the file containing the ambient module declaration
106489
106543
  // via a non-relative name, emit a type reference directive to that non-relative name, rather than
106490
106544
  // a relative path to the declaration file
106491
- recordTypeReferenceDirectivesIfNecessary([specifier]);
106545
+ recordTypeReferenceDirectivesIfNecessary([[specifier, /*mode*/ undefined]]);
106492
106546
  return;
106493
106547
  }
106494
106548
  var fileName = ts.getRelativePathToDirectoryOrUrl(outputFilePath, declFileName, host.getCurrentDirectory(), host.getCanonicalFileName,
@@ -111600,9 +111654,12 @@ var ts;
111600
111654
  for (var _d = 0, types_24 = types; _d < types_24.length; _d++) {
111601
111655
  var directive = types_24[_d];
111602
111656
  var pos = writer.getTextPos();
111603
- writeComment("/// <reference types=\"" + directive.fileName + "\" />");
111657
+ var resolutionMode = directive.resolutionMode && directive.resolutionMode !== (currentSourceFile === null || currentSourceFile === void 0 ? void 0 : currentSourceFile.impliedNodeFormat)
111658
+ ? "resolution-mode=\"" + (directive.resolutionMode === ts.ModuleKind.ESNext ? "import" : "require") + "\""
111659
+ : "";
111660
+ writeComment("/// <reference types=\"" + directive.fileName + "\" " + resolutionMode + "/>");
111604
111661
  if (bundleFileInfo)
111605
- bundleFileInfo.sections.push({ pos: pos, end: writer.getTextPos(), kind: "type" /* Type */, data: directive.fileName });
111662
+ 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 });
111606
111663
  writeLine();
111607
111664
  }
111608
111665
  for (var _e = 0, libs_1 = libs; _e < libs_1.length; _e++) {
@@ -114209,7 +114266,7 @@ var ts;
114209
114266
  }
114210
114267
  ts.flattenDiagnosticMessageText = flattenDiagnosticMessageText;
114211
114268
  /* @internal */
114212
- function loadWithLocalCache(names, containingFile, redirectedReference, loader) {
114269
+ function loadWithTypeDirectiveCache(names, containingFile, redirectedReference, containingFileMode, loader) {
114213
114270
  if (names.length === 0) {
114214
114271
  return [];
114215
114272
  }
@@ -114218,19 +114275,28 @@ var ts;
114218
114275
  for (var _i = 0, names_2 = names; _i < names_2.length; _i++) {
114219
114276
  var name = names_2[_i];
114220
114277
  var result = void 0;
114221
- if (cache.has(name)) {
114222
- result = cache.get(name);
114278
+ var mode = getModeForFileReference(name, containingFileMode);
114279
+ // We lower-case all type references because npm automatically lowercases all packages. See GH#9824.
114280
+ var strName = ts.isString(name) ? name : name.fileName.toLowerCase();
114281
+ var cacheKey = mode !== undefined ? mode + "|" + strName : strName;
114282
+ if (cache.has(cacheKey)) {
114283
+ result = cache.get(cacheKey);
114223
114284
  }
114224
114285
  else {
114225
- cache.set(name, result = loader(name, containingFile, redirectedReference));
114286
+ cache.set(cacheKey, result = loader(strName, containingFile, redirectedReference, mode));
114226
114287
  }
114227
114288
  resolutions.push(result);
114228
114289
  }
114229
114290
  return resolutions;
114230
114291
  }
114231
- ts.loadWithLocalCache = loadWithLocalCache;
114292
+ ts.loadWithTypeDirectiveCache = loadWithTypeDirectiveCache;
114232
114293
  ;
114233
114294
  /* @internal */
114295
+ function getModeForFileReference(ref, containingFileMode) {
114296
+ return (ts.isString(ref) ? containingFileMode : ref.resolutionMode) || containingFileMode;
114297
+ }
114298
+ ts.getModeForFileReference = getModeForFileReference;
114299
+ /* @internal */
114234
114300
  function getModeForResolutionAtIndex(file, index) {
114235
114301
  if (file.impliedNodeFormat === undefined)
114236
114302
  return undefined;
@@ -114333,7 +114399,7 @@ var ts;
114333
114399
  var _d, _e, _f, _g;
114334
114400
  var file = ts.Debug.checkDefined(getSourceFileByPath(ref.file));
114335
114401
  var kind = ref.kind, index = ref.index;
114336
- var pos, end, packageId;
114402
+ var pos, end, packageId, resolutionMode;
114337
114403
  switch (kind) {
114338
114404
  case ts.FileIncludeKind.Import:
114339
114405
  var importLiteral = getModuleNameStringLiteralAt(file, index);
@@ -114347,8 +114413,8 @@ var ts;
114347
114413
  (_a = file.referencedFiles[index], pos = _a.pos, end = _a.end);
114348
114414
  break;
114349
114415
  case ts.FileIncludeKind.TypeReferenceDirective:
114350
- (_b = file.typeReferenceDirectives[index], pos = _b.pos, end = _b.end);
114351
- 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;
114416
+ (_b = file.typeReferenceDirectives[index], pos = _b.pos, end = _b.end, resolutionMode = _b.resolutionMode);
114417
+ 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;
114352
114418
  break;
114353
114419
  case ts.FileIncludeKind.LibReferenceDirective:
114354
114420
  (_c = file.libReferenceDirectives[index], pos = _c.pos, end = _c.end);
@@ -114592,7 +114658,7 @@ var ts;
114592
114658
  var fileReasons = ts.createMultiMap();
114593
114659
  var cachedBindAndCheckDiagnosticsForFile = {};
114594
114660
  var cachedDeclarationDiagnosticsForFile = {};
114595
- var resolvedTypeReferenceDirectives = new ts.Map();
114661
+ var resolvedTypeReferenceDirectives = ts.createModeAwareCache();
114596
114662
  var fileProcessingDiagnostics;
114597
114663
  // The below settings are to track if a .js file should be add to the program if loaded via searching under node_modules.
114598
114664
  // This works as imported modules are discovered recursively in a depth first manner, specifically:
@@ -114645,12 +114711,12 @@ var ts;
114645
114711
  }
114646
114712
  var actualResolveTypeReferenceDirectiveNamesWorker;
114647
114713
  if (host.resolveTypeReferenceDirectives) {
114648
- actualResolveTypeReferenceDirectiveNamesWorker = function (typeDirectiveNames, containingFile, redirectedReference) { return host.resolveTypeReferenceDirectives(ts.Debug.checkEachDefined(typeDirectiveNames), containingFile, redirectedReference, options); };
114714
+ actualResolveTypeReferenceDirectiveNamesWorker = function (typeDirectiveNames, containingFile, redirectedReference, containingFileMode) { return host.resolveTypeReferenceDirectives(ts.Debug.checkEachDefined(typeDirectiveNames), containingFile, redirectedReference, options, containingFileMode); };
114649
114715
  }
114650
114716
  else {
114651
114717
  typeReferenceDirectiveResolutionCache = ts.createTypeReferenceDirectiveResolutionCache(currentDirectory, getCanonicalFileName, /*options*/ undefined, moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache());
114652
- var loader_2 = function (typesRef, containingFile, redirectedReference) { return ts.resolveTypeReferenceDirective(typesRef, containingFile, options, host, redirectedReference, typeReferenceDirectiveResolutionCache).resolvedTypeReferenceDirective; }; // TODO: GH#18217
114653
- actualResolveTypeReferenceDirectiveNamesWorker = function (typeReferenceDirectiveNames, containingFile, redirectedReference) { return loadWithLocalCache(ts.Debug.checkEachDefined(typeReferenceDirectiveNames), containingFile, redirectedReference, loader_2); };
114718
+ var loader_2 = function (typesRef, containingFile, redirectedReference, resolutionMode) { return ts.resolveTypeReferenceDirective(typesRef, containingFile, options, host, redirectedReference, typeReferenceDirectiveResolutionCache, resolutionMode).resolvedTypeReferenceDirective; }; // TODO: GH#18217
114719
+ actualResolveTypeReferenceDirectiveNamesWorker = function (typeReferenceDirectiveNames, containingFile, redirectedReference, containingFileMode) { return loadWithTypeDirectiveCache(ts.Debug.checkEachDefined(typeReferenceDirectiveNames), containingFile, redirectedReference, containingFileMode, loader_2); };
114654
114720
  }
114655
114721
  // Map from a stringified PackageId to the source file with that id.
114656
114722
  // Only one source file may have a given packageId. Others become redirects (see createRedirectSourceFile).
@@ -114747,7 +114813,8 @@ var ts;
114747
114813
  var containingFilename = ts.combinePaths(containingDirectory, ts.inferredTypesContainingFile);
114748
114814
  var resolutions = resolveTypeReferenceDirectiveNamesWorker(typeReferences, containingFilename);
114749
114815
  for (var i = 0; i < typeReferences.length; i++) {
114750
- processTypeReferenceDirective(typeReferences[i], resolutions[i], { kind: ts.FileIncludeKind.AutomaticTypeDirectiveFile, typeReference: typeReferences[i], packageId: (_c = resolutions[i]) === null || _c === void 0 ? void 0 : _c.packageId });
114816
+ // under node12/nodenext module resolution, load `types`/ata include names as cjs resolution results by passing an `undefined` mode
114817
+ 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 });
114751
114818
  }
114752
114819
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
114753
114820
  }
@@ -114907,9 +114974,10 @@ var ts;
114907
114974
  return [];
114908
114975
  var containingFileName = !ts.isString(containingFile) ? ts.getNormalizedAbsolutePath(containingFile.originalFileName, currentDirectory) : containingFile;
114909
114976
  var redirectedReference = !ts.isString(containingFile) ? getRedirectReferenceForResolution(containingFile) : undefined;
114977
+ var containingFileMode = !ts.isString(containingFile) ? containingFile.impliedNodeFormat : undefined;
114910
114978
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("program" /* Program */, "resolveTypeReferenceDirectiveNamesWorker", { containingFileName: containingFileName });
114911
114979
  ts.performance.mark("beforeResolveTypeReference");
114912
- var result = actualResolveTypeReferenceDirectiveNamesWorker(typeDirectiveNames, containingFileName, redirectedReference);
114980
+ var result = actualResolveTypeReferenceDirectiveNamesWorker(typeDirectiveNames, containingFileName, redirectedReference, containingFileMode);
114913
114981
  ts.performance.mark("afterResolveTypeReference");
114914
114982
  ts.performance.measure("ResolveTypeReference", "beforeResolveTypeReference", "afterResolveTypeReference");
114915
114983
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
@@ -115301,8 +115369,7 @@ var ts;
115301
115369
  else {
115302
115370
  newSourceFile.resolvedModules = oldSourceFile.resolvedModules;
115303
115371
  }
115304
- // We lower-case all type references because npm automatically lowercases all packages. See GH#9824.
115305
- var typesReferenceDirectives = ts.map(newSourceFile.typeReferenceDirectives, function (ref) { return ts.toFileNameLowerCase(ref.fileName); });
115372
+ var typesReferenceDirectives = newSourceFile.typeReferenceDirectives;
115306
115373
  var typeReferenceResolutions = resolveTypeReferenceDirectiveNamesWorker(typesReferenceDirectives, newSourceFile);
115307
115374
  // ensure that types resolutions are still correct
115308
115375
  var typeReferenceResolutionsChanged = ts.hasChangesInResolutions(typesReferenceDirectives, typeReferenceResolutions, oldSourceFile.resolvedTypeReferenceDirectiveNames, oldSourceFile, ts.typeDirectiveIsEqualTo);
@@ -116381,8 +116448,7 @@ var ts;
116381
116448
  });
116382
116449
  }
116383
116450
  function processTypeReferenceDirectives(file) {
116384
- // We lower-case all type references because npm automatically lowercases all packages. See GH#9824.
116385
- var typeDirectives = ts.map(file.typeReferenceDirectives, function (ref) { return ts.toFileNameLowerCase(ref.fileName); });
116451
+ var typeDirectives = file.typeReferenceDirectives;
116386
116452
  if (!typeDirectives) {
116387
116453
  return;
116388
116454
  }
@@ -116393,17 +116459,21 @@ var ts;
116393
116459
  // store resolved type directive on the file
116394
116460
  var fileName = ts.toFileNameLowerCase(ref.fileName);
116395
116461
  ts.setResolvedTypeReferenceDirective(file, fileName, resolvedTypeReferenceDirective);
116396
- processTypeReferenceDirective(fileName, resolvedTypeReferenceDirective, { kind: ts.FileIncludeKind.TypeReferenceDirective, file: file.path, index: index, });
116462
+ var mode = ref.resolutionMode || file.impliedNodeFormat;
116463
+ if (mode && ts.getEmitModuleResolutionKind(options) !== ts.ModuleResolutionKind.Node12 && ts.getEmitModuleResolutionKind(options) !== ts.ModuleResolutionKind.NodeNext) {
116464
+ programDiagnostics.add(ts.createDiagnosticForRange(file, ref, ts.Diagnostics.Resolution_modes_are_only_supported_when_moduleResolution_is_node12_or_nodenext));
116465
+ }
116466
+ processTypeReferenceDirective(fileName, mode, resolvedTypeReferenceDirective, { kind: ts.FileIncludeKind.TypeReferenceDirective, file: file.path, index: index, });
116397
116467
  }
116398
116468
  }
116399
- function processTypeReferenceDirective(typeReferenceDirective, resolvedTypeReferenceDirective, reason) {
116469
+ function processTypeReferenceDirective(typeReferenceDirective, mode, resolvedTypeReferenceDirective, reason) {
116400
116470
  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 });
116401
- processTypeReferenceDirectiveWorker(typeReferenceDirective, resolvedTypeReferenceDirective, reason);
116471
+ processTypeReferenceDirectiveWorker(typeReferenceDirective, mode, resolvedTypeReferenceDirective, reason);
116402
116472
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
116403
116473
  }
116404
- function processTypeReferenceDirectiveWorker(typeReferenceDirective, resolvedTypeReferenceDirective, reason) {
116474
+ function processTypeReferenceDirectiveWorker(typeReferenceDirective, mode, resolvedTypeReferenceDirective, reason) {
116405
116475
  // If we already found this library as a primary reference - nothing to do
116406
- var previousResolution = resolvedTypeReferenceDirectives.get(typeReferenceDirective);
116476
+ var previousResolution = resolvedTypeReferenceDirectives.get(typeReferenceDirective, mode);
116407
116477
  if (previousResolution && previousResolution.primary) {
116408
116478
  return;
116409
116479
  }
@@ -116442,7 +116512,7 @@ var ts;
116442
116512
  addFilePreprocessingFileExplainingDiagnostic(/*file*/ undefined, reason, ts.Diagnostics.Cannot_find_type_definition_file_for_0, [typeReferenceDirective]);
116443
116513
  }
116444
116514
  if (saveResolution) {
116445
- resolvedTypeReferenceDirectives.set(typeReferenceDirective, resolvedTypeReferenceDirective);
116515
+ resolvedTypeReferenceDirectives.set(typeReferenceDirective, mode, resolvedTypeReferenceDirective);
116446
116516
  }
116447
116517
  }
116448
116518
  function pathForLibFile(libFileName) {
@@ -119260,9 +119330,9 @@ var ts;
119260
119330
  });
119261
119331
  hasChangedAutomaticTypeDirectiveNames = false;
119262
119332
  }
119263
- function resolveModuleName(moduleName, containingFile, compilerOptions, host, redirectedReference) {
119333
+ function resolveModuleName(moduleName, containingFile, compilerOptions, host, redirectedReference, _containingSourceFile, mode) {
119264
119334
  var _a;
119265
- var primaryResult = ts.resolveModuleName(moduleName, containingFile, compilerOptions, host, moduleResolutionCache, redirectedReference);
119335
+ var primaryResult = ts.resolveModuleName(moduleName, containingFile, compilerOptions, host, moduleResolutionCache, redirectedReference, mode);
119266
119336
  // return result immediately only if global cache support is not enabled or if it is .ts, .tsx or .d.ts
119267
119337
  if (!resolutionHost.getGlobalCache) {
119268
119338
  return primaryResult;
@@ -119283,12 +119353,12 @@ var ts;
119283
119353
  // Default return the result from the first pass
119284
119354
  return primaryResult;
119285
119355
  }
119286
- function resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference) {
119287
- return ts.resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference, typeReferenceDirectiveResolutionCache);
119356
+ function resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference, _containingSourceFile, resolutionMode) {
119357
+ return ts.resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference, typeReferenceDirectiveResolutionCache, resolutionMode);
119288
119358
  }
119289
119359
  function resolveNamesWithLocalCache(_a) {
119290
119360
  var _b, _c, _d;
119291
- 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;
119361
+ 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;
119292
119362
  var path = resolutionHost.toPath(containingFile);
119293
119363
  var resolutionsInFile = cache.get(path) || cache.set(path, ts.createModeAwareCache()).get(path);
119294
119364
  var dirPath = ts.getDirectoryPath(path);
@@ -119310,8 +119380,15 @@ var ts;
119310
119380
  var seenNamesInFile = ts.createModeAwareCache();
119311
119381
  var i = 0;
119312
119382
  for (var _i = 0, names_4 = names; _i < names_4.length; _i++) {
119313
- var name = names_4[_i];
119314
- var mode = containingSourceFile ? ts.getModeForResolutionAtIndex(containingSourceFile, i) : undefined;
119383
+ var entry = names_4[_i];
119384
+ var name = ts.isString(entry) ? entry : entry.fileName.toLowerCase();
119385
+ // Imports supply a `containingSourceFile` but no `containingSourceFileMode` - it would be redundant
119386
+ // they require calculating the mode for a given import from it's position in the resolution table, since a given
119387
+ // import's syntax may override the file's default mode.
119388
+ // Type references instead supply a `containingSourceFileMode` and a non-string entry which contains
119389
+ // a default file mode override if applicable.
119390
+ var mode = !ts.isString(entry) ? ts.getModeForFileReference(entry, containingSourceFileMode) :
119391
+ containingSourceFile ? ts.getModeForResolutionAtIndex(containingSourceFile, i) : undefined;
119315
119392
  i++;
119316
119393
  var resolution = resolutionsInFile.get(name, mode);
119317
119394
  // Resolution is valid if it is present and not invalidated
@@ -119340,7 +119417,7 @@ var ts;
119340
119417
  }
119341
119418
  }
119342
119419
  else {
119343
- resolution = loader(name, containingFile, compilerOptions, ((_c = resolutionHost.getCompilerHost) === null || _c === void 0 ? void 0 : _c.call(resolutionHost)) || resolutionHost, redirectedReference, containingSourceFile);
119420
+ resolution = loader(name, containingFile, compilerOptions, ((_c = resolutionHost.getCompilerHost) === null || _c === void 0 ? void 0 : _c.call(resolutionHost)) || resolutionHost, redirectedReference, containingSourceFile, mode);
119344
119421
  perDirectoryResolution.set(name, mode, resolution);
119345
119422
  if (resolutionHost.onDiscoveredSymlink && resolutionIsSymlink(resolution)) {
119346
119423
  resolutionHost.onDiscoveredSymlink();
@@ -119404,7 +119481,7 @@ var ts;
119404
119481
  return oldResult.resolvedFileName === newResult.resolvedFileName;
119405
119482
  }
119406
119483
  }
119407
- function resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference) {
119484
+ function resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference, containingFileMode) {
119408
119485
  return resolveNamesWithLocalCache({
119409
119486
  names: typeDirectiveNames,
119410
119487
  containingFile: containingFile,
@@ -119414,6 +119491,7 @@ var ts;
119414
119491
  loader: resolveTypeReferenceDirective,
119415
119492
  getResolutionWithResolvedFileName: getResolvedTypeReferenceDirective,
119416
119493
  shouldRetryResolution: function (resolution) { return resolution.resolvedTypeReferenceDirective === undefined; },
119494
+ containingSourceFileMode: containingFileMode
119417
119495
  });
119418
119496
  }
119419
119497
  function resolveModuleNames(moduleNames, containingFile, reusedNames, redirectedReference, containingSourceFile) {
@@ -121322,7 +121400,7 @@ var ts;
121322
121400
  }
121323
121401
  return host.resolveTypeReferenceDirectives.apply(host, args);
121324
121402
  }) :
121325
- (function (typeDirectiveNames, containingFile, redirectedReference) { return resolutionCache.resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference); });
121403
+ (function (typeDirectiveNames, containingFile, redirectedReference, _options, containingFileMode) { return resolutionCache.resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference, containingFileMode); });
121326
121404
  var userProvidedResolution = !!host.resolveModuleNames || !!host.resolveTypeReferenceDirectives;
121327
121405
  builderProgram = readBuilderProgram(compilerOptions, compilerHost);
121328
121406
  synchronizeProgram();
@@ -122058,9 +122136,9 @@ var ts;
122058
122136
  compilerHost.getModuleResolutionCache = function () { return moduleResolutionCache; };
122059
122137
  }
122060
122138
  if (!compilerHost.resolveTypeReferenceDirectives) {
122061
- var loader_4 = function (moduleName, containingFile, redirectedReference) { return ts.resolveTypeReferenceDirective(moduleName, containingFile, state.projectCompilerOptions, compilerHost, redirectedReference, state.typeReferenceDirectiveResolutionCache).resolvedTypeReferenceDirective; };
122062
- compilerHost.resolveTypeReferenceDirectives = function (typeReferenceDirectiveNames, containingFile, redirectedReference) {
122063
- return ts.loadWithLocalCache(ts.Debug.checkEachDefined(typeReferenceDirectiveNames), containingFile, redirectedReference, loader_4);
122139
+ var loader_4 = function (moduleName, containingFile, redirectedReference, containingFileMode) { return ts.resolveTypeReferenceDirective(moduleName, containingFile, state.projectCompilerOptions, compilerHost, redirectedReference, state.typeReferenceDirectiveResolutionCache, containingFileMode).resolvedTypeReferenceDirective; };
122140
+ compilerHost.resolveTypeReferenceDirectives = function (typeReferenceDirectiveNames, containingFile, redirectedReference, _options, containingFileMode) {
122141
+ return ts.loadWithTypeDirectiveCache(ts.Debug.checkEachDefined(typeReferenceDirectiveNames), containingFile, redirectedReference, containingFileMode, loader_4);
122064
122142
  };
122065
122143
  }
122066
122144
  var _a = ts.createWatchFactory(hostWithWatch, options), watchFile = _a.watchFile, watchDirectory = _a.watchDirectory, writeLog = _a.writeLog;