typescript 4.6.0-dev.20220211 → 4.7.0-dev.20220217

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.
@@ -85,11 +85,11 @@ var ts;
85
85
  (function (ts) {
86
86
  // WARNING: The script `configurePrerelease.ts` uses a regexp to parse out these values.
87
87
  // If changing the text in this section, be sure to test `configurePrerelease` too.
88
- ts.versionMajorMinor = "4.6";
88
+ ts.versionMajorMinor = "4.7";
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.20220211";
92
+ ts.version = ts.versionMajorMinor + ".0-dev.20220217";
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";
@@ -4907,13 +4909,14 @@ var ts;
4907
4909
  // Flags that require TypeFlags.Object
4908
4910
  ObjectFlags[ObjectFlags["ContainsSpread"] = 4194304] = "ContainsSpread";
4909
4911
  ObjectFlags[ObjectFlags["ObjectRestType"] = 8388608] = "ObjectRestType";
4912
+ ObjectFlags[ObjectFlags["InstantiationExpressionType"] = 16777216] = "InstantiationExpressionType";
4910
4913
  /* @internal */
4911
- ObjectFlags[ObjectFlags["IsClassInstanceClone"] = 16777216] = "IsClassInstanceClone";
4914
+ ObjectFlags[ObjectFlags["IsClassInstanceClone"] = 33554432] = "IsClassInstanceClone";
4912
4915
  // Flags that require TypeFlags.Object and ObjectFlags.Reference
4913
4916
  /* @internal */
4914
- ObjectFlags[ObjectFlags["IdenticalBaseTypeCalculated"] = 33554432] = "IdenticalBaseTypeCalculated";
4917
+ ObjectFlags[ObjectFlags["IdenticalBaseTypeCalculated"] = 67108864] = "IdenticalBaseTypeCalculated";
4915
4918
  /* @internal */
4916
- ObjectFlags[ObjectFlags["IdenticalBaseTypeExists"] = 67108864] = "IdenticalBaseTypeExists";
4919
+ ObjectFlags[ObjectFlags["IdenticalBaseTypeExists"] = 134217728] = "IdenticalBaseTypeExists";
4917
4920
  // Flags that require TypeFlags.UnionOrIntersection or TypeFlags.Substitution
4918
4921
  /* @internal */
4919
4922
  ObjectFlags[ObjectFlags["IsGenericTypeComputed"] = 4194304] = "IsGenericTypeComputed";
@@ -5561,6 +5564,8 @@ var ts;
5561
5564
  BundleFileSectionKind["NoDefaultLib"] = "no-default-lib";
5562
5565
  BundleFileSectionKind["Reference"] = "reference";
5563
5566
  BundleFileSectionKind["Type"] = "type";
5567
+ BundleFileSectionKind["TypeResolutionModeRequire"] = "type-require";
5568
+ BundleFileSectionKind["TypeResolutionModeImport"] = "type-import";
5564
5569
  BundleFileSectionKind["Lib"] = "lib";
5565
5570
  BundleFileSectionKind["Prepend"] = "prepend";
5566
5571
  BundleFileSectionKind["Text"] = "text";
@@ -5677,7 +5682,8 @@ var ts;
5677
5682
  { name: "types", optional: true, captureSpan: true },
5678
5683
  { name: "lib", optional: true, captureSpan: true },
5679
5684
  { name: "path", optional: true, captureSpan: true },
5680
- { name: "no-default-lib", optional: true }
5685
+ { name: "no-default-lib", optional: true },
5686
+ { name: "resolution-mode", optional: true }
5681
5687
  ],
5682
5688
  kind: 1 /* TripleSlashXML */
5683
5689
  },
@@ -7625,18 +7631,6 @@ var ts;
7625
7631
  return getCanonicalFileName(nonCanonicalizedPath);
7626
7632
  }
7627
7633
  ts.toPath = toPath;
7628
- function normalizePathAndParts(path) {
7629
- path = normalizeSlashes(path);
7630
- var _a = reducePathComponents(getPathComponents(path)), root = _a[0], parts = _a.slice(1);
7631
- if (parts.length) {
7632
- var joinedParts = root + parts.join(ts.directorySeparator);
7633
- return { path: hasTrailingDirectorySeparator(path) ? ensureTrailingDirectorySeparator(joinedParts) : joinedParts, parts: parts };
7634
- }
7635
- else {
7636
- return { path: root, parts: parts };
7637
- }
7638
- }
7639
- ts.normalizePathAndParts = normalizePathAndParts;
7640
7634
  function removeTrailingDirectorySeparator(path) {
7641
7635
  if (hasTrailingDirectorySeparator(path)) {
7642
7636
  return path.substr(0, path.length - 1);
@@ -8070,6 +8064,8 @@ var ts;
8070
8064
  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."),
8071
8065
  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."),
8072
8066
  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."),
8067
+ 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}'."),
8068
+ 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'."),
8073
8069
  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."),
8074
8070
  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."),
8075
8071
  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."),
@@ -8138,7 +8134,6 @@ var ts;
8138
8134
  Unexpected_token_Did_you_mean_or_rbrace: diag(1381, ts.DiagnosticCategory.Error, "Unexpected_token_Did_you_mean_or_rbrace_1381", "Unexpected token. Did you mean `{'}'}` or `}`?"),
8139
8135
  Unexpected_token_Did_you_mean_or_gt: diag(1382, ts.DiagnosticCategory.Error, "Unexpected_token_Did_you_mean_or_gt_1382", "Unexpected token. Did you mean `{'>'}` or `>`?"),
8140
8136
  Only_named_exports_may_use_export_type: diag(1383, ts.DiagnosticCategory.Error, "Only_named_exports_may_use_export_type_1383", "Only named exports may use 'export type'."),
8141
- A_new_expression_with_type_arguments_must_always_be_followed_by_a_parenthesized_argument_list: diag(1384, ts.DiagnosticCategory.Error, "A_new_expression_with_type_arguments_must_always_be_followed_by_a_parenthesized_argument_list_1384", "A 'new' expression with type arguments must always be followed by a parenthesized argument list."),
8142
8137
  Function_type_notation_must_be_parenthesized_when_used_in_a_union_type: diag(1385, ts.DiagnosticCategory.Error, "Function_type_notation_must_be_parenthesized_when_used_in_a_union_type_1385", "Function type notation must be parenthesized when used in a union type."),
8143
8138
  Constructor_type_notation_must_be_parenthesized_when_used_in_a_union_type: diag(1386, ts.DiagnosticCategory.Error, "Constructor_type_notation_must_be_parenthesized_when_used_in_a_union_type_1386", "Constructor type notation must be parenthesized when used in a union type."),
8144
8139
  Function_type_notation_must_be_parenthesized_when_used_in_an_intersection_type: diag(1387, ts.DiagnosticCategory.Error, "Function_type_notation_must_be_parenthesized_when_used_in_an_intersection_type_1387", "Function type notation must be parenthesized when used in an intersection type."),
@@ -8203,6 +8198,8 @@ var ts;
8203
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."),
8204
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"),
8205
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`."),
8206
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."),
8207
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."),
8208
8205
  catch_or_finally_expected: diag(1472, ts.DiagnosticCategory.Error, "catch_or_finally_expected_1472", "'catch' or 'finally' expected."),
@@ -8522,6 +8519,7 @@ var ts;
8522
8519
  Cannot_assign_to_0_because_it_is_an_import: diag(2632, ts.DiagnosticCategory.Error, "Cannot_assign_to_0_because_it_is_an_import_2632", "Cannot assign to '{0}' because it is an import."),
8523
8520
  JSX_property_access_expressions_cannot_include_JSX_namespace_names: diag(2633, ts.DiagnosticCategory.Error, "JSX_property_access_expressions_cannot_include_JSX_namespace_names_2633", "JSX property access expressions cannot include JSX namespace names"),
8524
8521
  _0_index_signatures_are_incompatible: diag(2634, ts.DiagnosticCategory.Error, "_0_index_signatures_are_incompatible_2634", "'{0}' index signatures are incompatible."),
8522
+ Type_0_has_no_signatures_for_which_the_type_argument_list_is_applicable: diag(2635, ts.DiagnosticCategory.Error, "Type_0_has_no_signatures_for_which_the_type_argument_list_is_applicable_2635", "Type '{0}' has no signatures for which the type argument list is applicable."),
8525
8523
  Cannot_augment_module_0_with_value_exports_because_it_resolves_to_a_non_module_entity: diag(2649, ts.DiagnosticCategory.Error, "Cannot_augment_module_0_with_value_exports_because_it_resolves_to_a_non_module_entity_2649", "Cannot augment module '{0}' with value exports because it resolves to a non-module entity."),
8526
8524
  A_member_initializer_in_a_enum_declaration_cannot_reference_members_declared_after_it_including_members_defined_in_other_enums: diag(2651, ts.DiagnosticCategory.Error, "A_member_initializer_in_a_enum_declaration_cannot_reference_members_declared_after_it_including_memb_2651", "A member initializer in a enum declaration cannot reference members declared after it, including members defined in other enums."),
8527
8525
  Merged_declaration_0_cannot_include_a_default_export_declaration_Consider_adding_a_separate_export_default_0_declaration_instead: diag(2652, ts.DiagnosticCategory.Error, "Merged_declaration_0_cannot_include_a_default_export_declaration_Consider_adding_a_separate_export_d_2652", "Merged declaration '{0}' cannot include a default export declaration. Consider adding a separate 'export default {0}' declaration instead."),
@@ -13413,6 +13411,7 @@ var ts;
13413
13411
  case 110 /* TrueKeyword */:
13414
13412
  case 106 /* SuperKeyword */:
13415
13413
  case 229 /* NonNullExpression */:
13414
+ case 227 /* ExpressionWithTypeArguments */:
13416
13415
  case 230 /* MetaProperty */:
13417
13416
  case 100 /* ImportKeyword */: // technically this is only an Expression if it's in a CallExpression
13418
13417
  return true;
@@ -14086,7 +14085,11 @@ var ts;
14086
14085
  ts.Debug.assert(names.length === newResolutions.length);
14087
14086
  for (var i = 0; i < names.length; i++) {
14088
14087
  var newResolution = newResolutions[i];
14089
- var oldResolution = oldResolutions && oldResolutions.get(names[i], oldSourceFile && ts.getModeForResolutionAtIndex(oldSourceFile, i));
14088
+ var entry = names[i];
14089
+ // We lower-case all type references because npm automatically lowercases all packages. See GH#9824.
14090
+ var name = !ts.isString(entry) ? entry.fileName.toLowerCase() : entry;
14091
+ var mode = !ts.isString(entry) ? ts.getModeForFileReference(entry, oldSourceFile === null || oldSourceFile === void 0 ? void 0 : oldSourceFile.impliedNodeFormat) : oldSourceFile && ts.getModeForResolutionAtIndex(oldSourceFile, i);
14092
+ var oldResolution = oldResolutions && oldResolutions.get(name, mode);
14090
14093
  var changed = oldResolution
14091
14094
  ? !newResolution || !comparer(oldResolution, newResolution)
14092
14095
  : newResolution;
@@ -15122,7 +15125,7 @@ var ts;
15122
15125
  case 114 /* VoidKeyword */:
15123
15126
  return node.parent.kind !== 216 /* VoidExpression */;
15124
15127
  case 227 /* ExpressionWithTypeArguments */:
15125
- return !isExpressionWithTypeArgumentsInClassExtendsClause(node);
15128
+ return ts.isHeritageClause(node.parent) && !isExpressionWithTypeArgumentsInClassExtendsClause(node);
15126
15129
  case 162 /* TypeParameter */:
15127
15130
  return node.parent.kind === 194 /* MappedType */ || node.parent.kind === 189 /* InferType */;
15128
15131
  // Identifiers and qualified names may be type nodes, depending on their context. Climb
@@ -15159,7 +15162,7 @@ var ts;
15159
15162
  }
15160
15163
  switch (parent.kind) {
15161
15164
  case 227 /* ExpressionWithTypeArguments */:
15162
- return !isExpressionWithTypeArgumentsInClassExtendsClause(parent);
15165
+ return ts.isHeritageClause(parent.parent) && !isExpressionWithTypeArgumentsInClassExtendsClause(parent);
15163
15166
  case 162 /* TypeParameter */:
15164
15167
  return node === parent.constraint;
15165
15168
  case 342 /* JSDocTemplateTag */:
@@ -15862,7 +15865,7 @@ var ts;
15862
15865
  case 296 /* SpreadAssignment */:
15863
15866
  return true;
15864
15867
  case 227 /* ExpressionWithTypeArguments */:
15865
- return parent.expression === node && isExpressionWithTypeArgumentsInClassExtendsClause(parent);
15868
+ return parent.expression === node && !isPartOfTypeNode(parent);
15866
15869
  case 295 /* ShorthandPropertyAssignment */:
15867
15870
  return parent.objectAssignmentInitializer === node;
15868
15871
  default:
@@ -22849,16 +22852,18 @@ var ts;
22849
22852
  return updateConstructorTypeNode1(node, node.modifiers, typeParameters, parameters, type);
22850
22853
  }
22851
22854
  // @api
22852
- function createTypeQueryNode(exprName) {
22855
+ function createTypeQueryNode(exprName, typeArguments) {
22853
22856
  var node = createBaseNode(180 /* TypeQuery */);
22854
22857
  node.exprName = exprName;
22858
+ node.typeArguments = typeArguments && parenthesizerRules().parenthesizeTypeArguments(typeArguments);
22855
22859
  node.transformFlags = 1 /* ContainsTypeScript */;
22856
22860
  return node;
22857
22861
  }
22858
22862
  // @api
22859
- function updateTypeQueryNode(node, exprName) {
22863
+ function updateTypeQueryNode(node, exprName, typeArguments) {
22860
22864
  return node.exprName !== exprName
22861
- ? update(createTypeQueryNode(exprName), node)
22865
+ || node.typeArguments !== typeArguments
22866
+ ? update(createTypeQueryNode(exprName, typeArguments), node)
22862
22867
  : node;
22863
22868
  }
22864
22869
  // @api
@@ -26681,7 +26686,13 @@ var ts;
26681
26686
  referencedFiles = ts.append(referencedFiles, { pos: -1, end: -1, fileName: section.data });
26682
26687
  break;
26683
26688
  case "type" /* Type */:
26684
- typeReferenceDirectives = ts.append(typeReferenceDirectives, section.data);
26689
+ typeReferenceDirectives = ts.append(typeReferenceDirectives, { pos: -1, end: -1, fileName: section.data });
26690
+ break;
26691
+ case "type-import" /* TypeResolutionModeImport */:
26692
+ typeReferenceDirectives = ts.append(typeReferenceDirectives, { pos: -1, end: -1, fileName: section.data, resolutionMode: ts.ModuleKind.ESNext });
26693
+ break;
26694
+ case "type-require" /* TypeResolutionModeRequire */:
26695
+ typeReferenceDirectives = ts.append(typeReferenceDirectives, { pos: -1, end: -1, fileName: section.data, resolutionMode: ts.ModuleKind.CommonJS });
26685
26696
  break;
26686
26697
  case "lib" /* Lib */:
26687
26698
  libReferenceDirectives = ts.append(libReferenceDirectives, { pos: -1, end: -1, fileName: section.data });
@@ -26740,6 +26751,8 @@ var ts;
26740
26751
  case "no-default-lib" /* NoDefaultLib */:
26741
26752
  case "reference" /* Reference */:
26742
26753
  case "type" /* Type */:
26754
+ case "type-import" /* TypeResolutionModeImport */:
26755
+ case "type-require" /* TypeResolutionModeRequire */:
26743
26756
  case "lib" /* Lib */:
26744
26757
  syntheticReferences = ts.append(syntheticReferences, ts.setTextRange(ts.factory.createUnparsedSyntheticReference(section), section));
26745
26758
  break;
@@ -29974,7 +29987,8 @@ var ts;
29974
29987
  visitNode(cbNode, node.parameterName) ||
29975
29988
  visitNode(cbNode, node.type);
29976
29989
  case 180 /* TypeQuery */:
29977
- return visitNode(cbNode, node.exprName);
29990
+ return visitNode(cbNode, node.exprName) ||
29991
+ visitNodes(cbNode, cbNodes, node.typeArguments);
29978
29992
  case 181 /* TypeLiteral */:
29979
29993
  return visitNodes(cbNode, cbNodes, node.members);
29980
29994
  case 182 /* ArrayType */:
@@ -30653,7 +30667,7 @@ var ts;
30653
30667
  initializeState("", content, languageVersion, /*syntaxCursor*/ undefined, 1 /* JS */);
30654
30668
  // Prime the scanner.
30655
30669
  nextToken();
30656
- var entityName = parseEntityName(/*allowReservedWords*/ true);
30670
+ var entityName = parseEntityName(/*allowReservedWords*/ true, /*allowPrivateIdentifiers*/ false);
30657
30671
  var isInvalid = token() === 1 /* EndOfFileToken */ && !parseDiagnostics.length;
30658
30672
  clearState();
30659
30673
  return isInvalid ? entityName : undefined;
@@ -32230,7 +32244,7 @@ var ts;
32230
32244
  }
32231
32245
  return createMissingList();
32232
32246
  }
32233
- function parseEntityName(allowReservedWords, diagnosticMessage) {
32247
+ function parseEntityName(allowReservedWords, allowPrivateIdentifiers, diagnosticMessage) {
32234
32248
  var pos = getNodePos();
32235
32249
  var entity = allowReservedWords ? parseIdentifierName(diagnosticMessage) : parseIdentifier(diagnosticMessage);
32236
32250
  var dotPos = getNodePos();
@@ -32241,7 +32255,7 @@ var ts;
32241
32255
  break;
32242
32256
  }
32243
32257
  dotPos = getNodePos();
32244
- entity = finishNode(factory.createQualifiedName(entity, parseRightSideOfDot(allowReservedWords, /* allowPrivateIdentifiers */ false)), pos);
32258
+ entity = finishNode(factory.createQualifiedName(entity, parseRightSideOfDot(allowReservedWords, allowPrivateIdentifiers)), pos);
32245
32259
  }
32246
32260
  return entity;
32247
32261
  }
@@ -32374,7 +32388,7 @@ var ts;
32374
32388
  }
32375
32389
  // TYPES
32376
32390
  function parseEntityNameOfTypeReference() {
32377
- return parseEntityName(/*allowReservedWords*/ true, ts.Diagnostics.Type_expected);
32391
+ return parseEntityName(/*allowReservedWords*/ true, /*allowPrivateIdentifiers*/ false, ts.Diagnostics.Type_expected);
32378
32392
  }
32379
32393
  function parseTypeArgumentsOfTypeReference() {
32380
32394
  if (!scanner.hasPrecedingLineBreak() && reScanLessThanToken() === 29 /* LessThanToken */) {
@@ -32507,7 +32521,9 @@ var ts;
32507
32521
  function parseTypeQuery() {
32508
32522
  var pos = getNodePos();
32509
32523
  parseExpected(112 /* TypeOfKeyword */);
32510
- return finishNode(factory.createTypeQueryNode(parseEntityName(/*allowReservedWords*/ true)), pos);
32524
+ var entityName = parseEntityName(/*allowReservedWords*/ true, /*allowPrivateIdentifiers*/ true);
32525
+ var typeArguments = tryParseTypeArguments();
32526
+ return finishNode(factory.createTypeQueryNode(entityName, typeArguments), pos);
32511
32527
  }
32512
32528
  function parseTypeParameter() {
32513
32529
  var pos = getNodePos();
@@ -34577,20 +34593,30 @@ var ts;
34577
34593
  expression = parsePropertyAccessExpressionRest(pos, expression, questionDotToken);
34578
34594
  continue;
34579
34595
  }
34580
- if (!questionDotToken && token() === 53 /* ExclamationToken */ && !scanner.hasPrecedingLineBreak()) {
34581
- nextToken();
34582
- expression = finishNode(factory.createNonNullExpression(expression), pos);
34583
- continue;
34584
- }
34585
34596
  // when in the [Decorator] context, we do not parse ElementAccess as it could be part of a ComputedPropertyName
34586
34597
  if ((questionDotToken || !inDecoratorContext()) && parseOptional(22 /* OpenBracketToken */)) {
34587
34598
  expression = parseElementAccessExpressionRest(pos, expression, questionDotToken);
34588
34599
  continue;
34589
34600
  }
34590
34601
  if (isTemplateStartOfTaggedTemplate()) {
34591
- expression = parseTaggedTemplateRest(pos, expression, questionDotToken, /*typeArguments*/ undefined);
34602
+ // Absorb type arguments into TemplateExpression when preceding expression is ExpressionWithTypeArguments
34603
+ expression = !questionDotToken && expression.kind === 227 /* ExpressionWithTypeArguments */ ?
34604
+ parseTaggedTemplateRest(pos, expression.expression, questionDotToken, expression.typeArguments) :
34605
+ parseTaggedTemplateRest(pos, expression, questionDotToken, /*typeArguments*/ undefined);
34592
34606
  continue;
34593
34607
  }
34608
+ if (!questionDotToken) {
34609
+ if (token() === 53 /* ExclamationToken */ && !scanner.hasPrecedingLineBreak()) {
34610
+ nextToken();
34611
+ expression = finishNode(factory.createNonNullExpression(expression), pos);
34612
+ continue;
34613
+ }
34614
+ var typeArguments = tryParse(parseTypeArgumentsInExpression);
34615
+ if (typeArguments) {
34616
+ expression = finishNode(factory.createExpressionWithTypeArguments(expression, typeArguments), pos);
34617
+ continue;
34618
+ }
34619
+ }
34594
34620
  return expression;
34595
34621
  }
34596
34622
  }
@@ -34610,38 +34636,30 @@ var ts;
34610
34636
  function parseCallExpressionRest(pos, expression) {
34611
34637
  while (true) {
34612
34638
  expression = parseMemberExpressionRest(pos, expression, /*allowOptionalChain*/ true);
34639
+ var typeArguments = void 0;
34613
34640
  var questionDotToken = parseOptionalToken(28 /* QuestionDotToken */);
34614
- // handle 'foo<<T>()'
34615
- // parse template arguments only in TypeScript files (not in JavaScript files).
34616
- if ((contextFlags & 131072 /* JavaScriptFile */) === 0 && (token() === 29 /* LessThanToken */ || token() === 47 /* LessThanLessThanToken */)) {
34617
- // See if this is the start of a generic invocation. If so, consume it and
34618
- // keep checking for postfix expressions. Otherwise, it's just a '<' that's
34619
- // part of an arithmetic expression. Break out so we consume it higher in the
34620
- // stack.
34621
- var typeArguments = tryParse(parseTypeArgumentsInExpression);
34622
- if (typeArguments) {
34623
- if (isTemplateStartOfTaggedTemplate()) {
34624
- expression = parseTaggedTemplateRest(pos, expression, questionDotToken, typeArguments);
34625
- continue;
34626
- }
34627
- var argumentList = parseArgumentList();
34628
- var callExpr = questionDotToken || tryReparseOptionalChain(expression) ?
34629
- factory.createCallChain(expression, questionDotToken, typeArguments, argumentList) :
34630
- factory.createCallExpression(expression, typeArguments, argumentList);
34631
- expression = finishNode(callExpr, pos);
34641
+ if (questionDotToken) {
34642
+ typeArguments = tryParse(parseTypeArgumentsInExpression);
34643
+ if (isTemplateStartOfTaggedTemplate()) {
34644
+ expression = parseTaggedTemplateRest(pos, expression, questionDotToken, typeArguments);
34632
34645
  continue;
34633
34646
  }
34634
34647
  }
34635
- else if (token() === 20 /* OpenParenToken */) {
34648
+ if (typeArguments || token() === 20 /* OpenParenToken */) {
34649
+ // Absorb type arguments into CallExpression when preceding expression is ExpressionWithTypeArguments
34650
+ if (!questionDotToken && expression.kind === 227 /* ExpressionWithTypeArguments */) {
34651
+ typeArguments = expression.typeArguments;
34652
+ expression = expression.expression;
34653
+ }
34636
34654
  var argumentList = parseArgumentList();
34637
34655
  var callExpr = questionDotToken || tryReparseOptionalChain(expression) ?
34638
- factory.createCallChain(expression, questionDotToken, /*typeArguments*/ undefined, argumentList) :
34639
- factory.createCallExpression(expression, /*typeArguments*/ undefined, argumentList);
34656
+ factory.createCallChain(expression, questionDotToken, typeArguments, argumentList) :
34657
+ factory.createCallExpression(expression, typeArguments, argumentList);
34640
34658
  expression = finishNode(callExpr, pos);
34641
34659
  continue;
34642
34660
  }
34643
34661
  if (questionDotToken) {
34644
- // We failed to parse anything, so report a missing identifier here.
34662
+ // We parsed `?.` but then failed to parse anything, so report a missing identifier here.
34645
34663
  var name = createMissingNode(79 /* Identifier */, /*reportAtCurrentPosition*/ false, ts.Diagnostics.Identifier_expected);
34646
34664
  expression = finishNode(factory.createPropertyAccessChain(expression, questionDotToken, name), pos);
34647
34665
  }
@@ -34669,21 +34687,25 @@ var ts;
34669
34687
  // If it doesn't have the closing `>` then it's definitely not an type argument list.
34670
34688
  return undefined;
34671
34689
  }
34672
- // If we have a '<', then only parse this as a argument list if the type arguments
34673
- // are complete and we have an open paren. if we don't, rewind and return nothing.
34674
- return typeArguments && canFollowTypeArgumentsInExpression()
34675
- ? typeArguments
34676
- : undefined;
34690
+ // We successfully parsed a type argument list. The next token determines whether we want to
34691
+ // treat it as such. If the type argument list is followed by `(` or a template literal, as in
34692
+ // `f<number>(42)`, we favor the type argument interpretation even though JavaScript would view
34693
+ // it as a relational expression.
34694
+ return typeArguments && canFollowTypeArgumentsInExpression() ? typeArguments : undefined;
34677
34695
  }
34678
34696
  function canFollowTypeArgumentsInExpression() {
34679
34697
  switch (token()) {
34698
+ // These tokens can follow a type argument list in a call expression.
34680
34699
  case 20 /* OpenParenToken */: // foo<x>(
34681
34700
  case 14 /* NoSubstitutionTemplateLiteral */: // foo<T> `...`
34682
34701
  case 15 /* TemplateHead */: // foo<T> `...${100}...`
34683
- // these are the only tokens can legally follow a type argument
34684
- // list. So we definitely want to treat them as type arg lists.
34702
+ // These tokens can't follow in a call expression, nor can they start an
34703
+ // expression. So, consider the type argument list part of an instantiation
34704
+ // expression.
34685
34705
  // falls through
34706
+ case 27 /* CommaToken */: // foo<x>,
34686
34707
  case 24 /* DotToken */: // foo<x>.
34708
+ case 28 /* QuestionDotToken */: // foo<x>?.
34687
34709
  case 21 /* CloseParenToken */: // foo<x>)
34688
34710
  case 23 /* CloseBracketToken */: // foo<x>]
34689
34711
  case 58 /* ColonToken */: // foo<x>:
@@ -34701,20 +34723,10 @@ var ts;
34701
34723
  case 51 /* BarToken */: // foo<x> |
34702
34724
  case 19 /* CloseBraceToken */: // foo<x> }
34703
34725
  case 1 /* EndOfFileToken */: // foo<x>
34704
- // these cases can't legally follow a type arg list. However, they're not legal
34705
- // expressions either. The user is probably in the middle of a generic type. So
34706
- // treat it as such.
34707
34726
  return true;
34708
- case 27 /* CommaToken */: // foo<x>,
34709
- case 18 /* OpenBraceToken */: // foo<x> {
34710
- // We don't want to treat these as type arguments. Otherwise we'll parse this
34711
- // as an invocation expression. Instead, we want to parse out the expression
34712
- // in isolation from the type arguments.
34713
- // falls through
34714
- default:
34715
- // Anything else treat as an expression.
34716
- return false;
34717
34727
  }
34728
+ // Treat anything else as an expression.
34729
+ return false;
34718
34730
  }
34719
34731
  function parsePrimaryExpression() {
34720
34732
  switch (token()) {
@@ -34895,26 +34907,15 @@ var ts;
34895
34907
  return finishNode(factory.createMetaProperty(103 /* NewKeyword */, name), pos);
34896
34908
  }
34897
34909
  var expressionPos = getNodePos();
34898
- var expression = parsePrimaryExpression();
34910
+ var expression = parseMemberExpressionRest(expressionPos, parsePrimaryExpression(), /*allowOptionalChain*/ false);
34899
34911
  var typeArguments;
34900
- while (true) {
34901
- expression = parseMemberExpressionRest(expressionPos, expression, /*allowOptionalChain*/ false);
34902
- typeArguments = tryParse(parseTypeArgumentsInExpression);
34903
- if (isTemplateStartOfTaggedTemplate()) {
34904
- ts.Debug.assert(!!typeArguments, "Expected a type argument list; all plain tagged template starts should be consumed in 'parseMemberExpressionRest'");
34905
- expression = parseTaggedTemplateRest(expressionPos, expression, /*optionalChain*/ undefined, typeArguments);
34906
- typeArguments = undefined;
34907
- }
34908
- break;
34909
- }
34910
- var argumentsArray;
34911
- if (token() === 20 /* OpenParenToken */) {
34912
- argumentsArray = parseArgumentList();
34913
- }
34914
- else if (typeArguments) {
34915
- parseErrorAt(pos, scanner.getStartPos(), ts.Diagnostics.A_new_expression_with_type_arguments_must_always_be_followed_by_a_parenthesized_argument_list);
34912
+ // Absorb type arguments into NewExpression when preceding expression is ExpressionWithTypeArguments
34913
+ if (expression.kind === 227 /* ExpressionWithTypeArguments */) {
34914
+ typeArguments = expression.typeArguments;
34915
+ expression = expression.expression;
34916
34916
  }
34917
- return finishNode(factory.createNewExpression(expression, typeArguments, argumentsArray), pos);
34917
+ var argumentList = token() === 20 /* OpenParenToken */ ? parseArgumentList() : undefined;
34918
+ return finishNode(factory.createNewExpression(expression, typeArguments, argumentList), pos);
34918
34919
  }
34919
34920
  // STATEMENTS
34920
34921
  function parseBlock(ignoreMissingOpenBrace, diagnosticMessage) {
@@ -35078,11 +35079,12 @@ var ts;
35078
35079
  }
35079
35080
  function parseCaseClause() {
35080
35081
  var pos = getNodePos();
35082
+ var hasJSDoc = hasPrecedingJSDocComment();
35081
35083
  parseExpected(82 /* CaseKeyword */);
35082
35084
  var expression = allowInAnd(parseExpression);
35083
35085
  parseExpected(58 /* ColonToken */);
35084
35086
  var statements = parseList(3 /* SwitchClauseStatements */, parseStatement);
35085
- return finishNode(factory.createCaseClause(expression, statements), pos);
35087
+ return withJSDoc(finishNode(factory.createCaseClause(expression, statements), pos), hasJSDoc);
35086
35088
  }
35087
35089
  function parseDefaultClause() {
35088
35090
  var pos = getNodePos();
@@ -36002,6 +36004,9 @@ var ts;
36002
36004
  function parseExpressionWithTypeArguments() {
36003
36005
  var pos = getNodePos();
36004
36006
  var expression = parseLeftHandSideExpressionOrHigher();
36007
+ if (expression.kind === 227 /* ExpressionWithTypeArguments */) {
36008
+ return expression;
36009
+ }
36005
36010
  var typeArguments = tryParseTypeArguments();
36006
36011
  return finishNode(factory.createExpressionWithTypeArguments(expression, typeArguments), pos);
36007
36012
  }
@@ -36245,7 +36250,7 @@ var ts;
36245
36250
  function parseModuleReference() {
36246
36251
  return isExternalModuleReference()
36247
36252
  ? parseExternalModuleReference()
36248
- : parseEntityName(/*allowReservedWords*/ false);
36253
+ : parseEntityName(/*allowReservedWords*/ false, /*allowPrivateIdentifiers*/ false);
36249
36254
  }
36250
36255
  function parseExternalModuleReference() {
36251
36256
  var pos = getNodePos();
@@ -36527,7 +36532,7 @@ var ts;
36527
36532
  var pos = getNodePos();
36528
36533
  var hasBrace = parseOptional(18 /* OpenBraceToken */);
36529
36534
  var p2 = getNodePos();
36530
- var entityName = parseEntityName(/* allowReservedWords*/ false);
36535
+ var entityName = parseEntityName(/* allowReservedWords*/ false, /*allowPrivateIdentifiers*/ false);
36531
36536
  while (token() === 80 /* PrivateIdentifier */) {
36532
36537
  reScanHashToken(); // rescan #id as # id
36533
36538
  nextTokenJSDoc(); // then skip the #
@@ -36970,7 +36975,7 @@ var ts;
36970
36975
  // parseEntityName logs an error for non-identifier, so create a MissingNode ourselves to avoid the error
36971
36976
  var p2 = getNodePos();
36972
36977
  var name = ts.tokenIsIdentifierOrKeyword(token())
36973
- ? parseEntityName(/*allowReservedWords*/ true)
36978
+ ? parseEntityName(/*allowReservedWords*/ true, /*allowPrivateIdentifiers*/ false)
36974
36979
  : undefined;
36975
36980
  if (name) {
36976
36981
  while (token() === 80 /* PrivateIdentifier */) {
@@ -36995,11 +37000,13 @@ var ts;
36995
37000
  && nextTokenJSDoc() === 59 /* AtToken */
36996
37001
  && ts.tokenIsIdentifierOrKeyword(nextTokenJSDoc())) {
36997
37002
  var kind = scanner.getTokenValue();
36998
- if (kind === "link" || kind === "linkcode" || kind === "linkplain") {
37003
+ if (isJSDocLinkTag(kind))
36999
37004
  return kind;
37000
- }
37001
37005
  }
37002
37006
  }
37007
+ function isJSDocLinkTag(kind) {
37008
+ return kind === "link" || kind === "linkcode" || kind === "linkplain";
37009
+ }
37003
37010
  function parseUnknownTag(start, tagName, indent, indentText) {
37004
37011
  return finishNode(factory.createJSDocUnknownTag(tagName, parseTrailingTagComments(start, getNodePos(), indent, indentText)), start);
37005
37012
  }
@@ -37105,7 +37112,7 @@ var ts;
37105
37112
  }
37106
37113
  function parseSeeTag(start, tagName, indent, indentText) {
37107
37114
  var isMarkdownOrJSDocLink = token() === 22 /* OpenBracketToken */
37108
- || lookAhead(function () { return nextTokenJSDoc() === 59 /* AtToken */ && ts.tokenIsIdentifierOrKeyword(nextTokenJSDoc()) && scanner.getTokenValue() === "link"; });
37115
+ || lookAhead(function () { return nextTokenJSDoc() === 59 /* AtToken */ && ts.tokenIsIdentifierOrKeyword(nextTokenJSDoc()) && isJSDocLinkTag(scanner.getTokenValue()); });
37109
37116
  var nameExpression = isMarkdownOrJSDocLink ? undefined : parseJSDocNameReference();
37110
37117
  var comments = indent !== undefined && indentText !== undefined ? parseTrailingTagComments(start, getNodePos(), indent, indentText) : undefined;
37111
37118
  return finishNode(factory.createJSDocSeeTag(tagName, nameExpression, comments), start);
@@ -37972,6 +37979,19 @@ var ts;
37972
37979
  return ts.fileExtensionIsOneOf(fileName, [".d.ts" /* Dts */, ".d.mts" /* Dmts */, ".d.cts" /* Dcts */]);
37973
37980
  }
37974
37981
  ts.isDeclarationFileName = isDeclarationFileName;
37982
+ function parseResolutionMode(mode, pos, end, reportDiagnostic) {
37983
+ if (!mode) {
37984
+ return undefined;
37985
+ }
37986
+ if (mode === "import") {
37987
+ return ts.ModuleKind.ESNext;
37988
+ }
37989
+ if (mode === "require") {
37990
+ return ts.ModuleKind.CommonJS;
37991
+ }
37992
+ reportDiagnostic(pos, end - pos, ts.Diagnostics.resolution_mode_should_be_either_require_or_import);
37993
+ return undefined;
37994
+ }
37975
37995
  /*@internal*/
37976
37996
  function processCommentPragmas(context, sourceText) {
37977
37997
  var pragmas = [];
@@ -38014,12 +38034,13 @@ var ts;
38014
38034
  var typeReferenceDirectives_1 = context.typeReferenceDirectives;
38015
38035
  var libReferenceDirectives_1 = context.libReferenceDirectives;
38016
38036
  ts.forEach(ts.toArray(entryOrList), function (arg) {
38017
- var _a = arg.arguments, types = _a.types, lib = _a.lib, path = _a.path;
38037
+ var _a = arg.arguments, types = _a.types, lib = _a.lib, path = _a.path, res = _a["resolution-mode"];
38018
38038
  if (arg.arguments["no-default-lib"]) {
38019
38039
  context.hasNoDefaultLib = true;
38020
38040
  }
38021
38041
  else if (types) {
38022
- typeReferenceDirectives_1.push({ pos: types.pos, end: types.end, fileName: types.value });
38042
+ var parsed = parseResolutionMode(res, types.pos, types.end, reportDiagnostic);
38043
+ typeReferenceDirectives_1.push(__assign({ pos: types.pos, end: types.end, fileName: types.value }, (parsed ? { resolutionMode: parsed } : {})));
38023
38044
  }
38024
38045
  else if (lib) {
38025
38046
  libReferenceDirectives_1.push({ pos: lib.pos, end: lib.end, fileName: lib.value });
@@ -41597,14 +41618,14 @@ var ts;
41597
41618
  * This is possible in case if resolution is performed for directives specified via 'types' parameter. In this case initial path for secondary lookups
41598
41619
  * is assumed to be the same as root directory of the project.
41599
41620
  */
41600
- function resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference, cache) {
41621
+ function resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference, cache, resolutionMode) {
41601
41622
  var traceEnabled = isTraceEnabled(options, host);
41602
41623
  if (redirectedReference) {
41603
41624
  options = redirectedReference.commandLine.options;
41604
41625
  }
41605
41626
  var containingDirectory = containingFile ? ts.getDirectoryPath(containingFile) : undefined;
41606
41627
  var perFolderCache = containingDirectory ? cache && cache.getOrCreateCacheForDirectory(containingDirectory, redirectedReference) : undefined;
41607
- var result = perFolderCache && perFolderCache.get(typeReferenceDirectiveName, /*mode*/ undefined);
41628
+ var result = perFolderCache && perFolderCache.get(typeReferenceDirectiveName, /*mode*/ resolutionMode);
41608
41629
  if (result) {
41609
41630
  if (traceEnabled) {
41610
41631
  trace(host, ts.Diagnostics.Resolving_type_reference_directive_0_containing_file_1, typeReferenceDirectiveName, containingFile);
@@ -41639,7 +41660,18 @@ var ts;
41639
41660
  }
41640
41661
  var failedLookupLocations = [];
41641
41662
  var features = getDefaultNodeResolutionFeatures(options);
41642
- var moduleResolutionState = { compilerOptions: options, host: host, traceEnabled: traceEnabled, failedLookupLocations: failedLookupLocations, packageJsonInfoCache: cache, features: features, conditions: ["node", "require", "types"] };
41663
+ // Unlike `import` statements, whose mode-calculating APIs are all guaranteed to return `undefined` if we're in an un-mode-ed module resolution
41664
+ // setting, type references will return their target mode regardless of options because of how the parser works, so we guard against the mode being
41665
+ // set in a non-modal module resolution setting here. Do note that our behavior is not particularly well defined when these mode-overriding imports
41666
+ // 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,
41667
+ // 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
41668
+ // resolution" should be (`node12`? `nodenext`?). As such, witnessing a mode-overriding triple-slash reference in a non-modal module resolution
41669
+ // context should _probably_ be an error - and that should likely be handled by the `Program` (which is what we do).
41670
+ if (resolutionMode === ts.ModuleKind.ESNext && (ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Node12 || ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext)) {
41671
+ features |= NodeResolutionFeatures.EsmMode;
41672
+ }
41673
+ var conditions = features & NodeResolutionFeatures.Exports ? features & NodeResolutionFeatures.EsmMode ? ["node", "import", "types"] : ["node", "require", "types"] : [];
41674
+ var moduleResolutionState = { compilerOptions: options, host: host, traceEnabled: traceEnabled, failedLookupLocations: failedLookupLocations, packageJsonInfoCache: cache, features: features, conditions: conditions };
41643
41675
  var resolved = primaryLookup();
41644
41676
  var primary = true;
41645
41677
  if (!resolved) {
@@ -41659,7 +41691,7 @@ var ts;
41659
41691
  };
41660
41692
  }
41661
41693
  result = { resolvedTypeReferenceDirective: resolvedTypeReferenceDirective, failedLookupLocations: failedLookupLocations };
41662
- perFolderCache === null || perFolderCache === void 0 ? void 0 : perFolderCache.set(typeReferenceDirectiveName, /*mode*/ undefined, result);
41694
+ perFolderCache === null || perFolderCache === void 0 ? void 0 : perFolderCache.set(typeReferenceDirectiveName, /*mode*/ resolutionMode, result);
41663
41695
  if (traceEnabled)
41664
41696
  traceResult(result);
41665
41697
  return result;
@@ -41710,7 +41742,7 @@ var ts;
41710
41742
  result_4 = searchResult && searchResult.value;
41711
41743
  }
41712
41744
  else {
41713
- var candidate = ts.normalizePathAndParts(ts.combinePaths(initialLocationForSecondaryLookup, typeReferenceDirectiveName)).path;
41745
+ var candidate = normalizePathForCJSResolution(initialLocationForSecondaryLookup, typeReferenceDirectiveName).path;
41714
41746
  result_4 = nodeLoadModuleByRelativeName(Extensions.DtsOnly, candidate, /*onlyRecordFailures*/ false, moduleResolutionState, /*considerPackageJson*/ true);
41715
41747
  }
41716
41748
  return resolvedTypeScriptOnly(result_4);
@@ -41945,7 +41977,11 @@ var ts;
41945
41977
  ts.Debug.assert(keys.length === values.length);
41946
41978
  var map = createModeAwareCache();
41947
41979
  for (var i = 0; i < keys.length; ++i) {
41948
- map.set(keys[i], ts.getModeForResolutionAtIndex(file, i), values[i]);
41980
+ var entry = keys[i];
41981
+ // We lower-case all type references because npm automatically lowercases all packages. See GH#9824.
41982
+ var name = !ts.isString(entry) ? entry.fileName.toLowerCase() : entry;
41983
+ var mode = !ts.isString(entry) ? entry.resolutionMode || file.impliedNodeFormat : ts.getModeForResolutionAtIndex(file, i);
41984
+ map.set(name, mode, values[i]);
41949
41985
  }
41950
41986
  return map;
41951
41987
  }
@@ -42413,13 +42449,25 @@ var ts;
42413
42449
  return { value: resolvedValue && { resolved: resolvedValue, isExternalLibraryImport: true } };
42414
42450
  }
42415
42451
  else {
42416
- var _a = ts.normalizePathAndParts(ts.combinePaths(containingDirectory, moduleName)), candidate = _a.path, parts = _a.parts;
42452
+ var _a = normalizePathForCJSResolution(containingDirectory, moduleName), candidate = _a.path, parts = _a.parts;
42417
42453
  var resolved_2 = nodeLoadModuleByRelativeName(extensions, candidate, /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true);
42418
42454
  // Treat explicit "node_modules" import as an external library import.
42419
42455
  return resolved_2 && toSearchResult({ resolved: resolved_2, isExternalLibraryImport: ts.contains(parts, "node_modules") });
42420
42456
  }
42421
42457
  }
42422
42458
  }
42459
+ // If you import from "." inside a containing directory "/foo", the result of `normalizePath`
42460
+ // would be "/foo", but this loses the information that `foo` is a directory and we intended
42461
+ // to look inside of it. The Node CommonJS resolution algorithm doesn't call this out
42462
+ // (https://nodejs.org/api/modules.html#all-together), but it seems that module paths ending
42463
+ // in `.` are actually normalized to `./` before proceeding with the resolution algorithm.
42464
+ function normalizePathForCJSResolution(containingDirectory, moduleName) {
42465
+ var combined = ts.combinePaths(containingDirectory, moduleName);
42466
+ var parts = ts.getPathComponents(combined);
42467
+ var lastPart = ts.lastOrUndefined(parts);
42468
+ var path = lastPart === "." || lastPart === ".." ? ts.ensureTrailingDirectorySeparator(ts.normalizePath(combined)) : ts.normalizePath(combined);
42469
+ return { path: path, parts: parts };
42470
+ }
42423
42471
  function realPath(path, host, traceEnabled) {
42424
42472
  if (!host.realpath) {
42425
42473
  return path;
@@ -42461,7 +42509,13 @@ var ts;
42461
42509
  onlyRecordFailures = true;
42462
42510
  }
42463
42511
  }
42464
- return loadNodeModuleFromDirectory(extensions, candidate, onlyRecordFailures, state, considerPackageJson);
42512
+ // esm mode relative imports shouldn't do any directory lookups (either inside `package.json`
42513
+ // files or implicit `index.js`es). This is a notable depature from cjs norms, where `./foo/pkg`
42514
+ // could have been redirected by `./foo/pkg/package.json` to an arbitrary location!
42515
+ if (!(state.features & NodeResolutionFeatures.EsmMode)) {
42516
+ return loadNodeModuleFromDirectory(extensions, candidate, onlyRecordFailures, state, considerPackageJson);
42517
+ }
42518
+ return undefined;
42465
42519
  }
42466
42520
  /*@internal*/
42467
42521
  ts.nodeModulesPathPart = "/node_modules/";
@@ -42828,7 +42882,16 @@ var ts;
42828
42882
  // Even if extensions is DtsOnly, we can still look up a .ts file as a result of package.json "types"
42829
42883
  var nextExtensions = extensions === Extensions.DtsOnly ? Extensions.TypeScript : extensions;
42830
42884
  // Don't do package.json lookup recursively, because Node.js' package lookup doesn't.
42831
- return nodeLoadModuleByRelativeName(nextExtensions, candidate, onlyRecordFailures, state, /*considerPackageJson*/ false);
42885
+ // Disable `EsmMode` for the resolution of the package path for cjs-mode packages (so the `main` field can omit extensions)
42886
+ // (technically it only emits a deprecation warning in esm packages right now, but that's probably
42887
+ // enough to mean we don't need to support it)
42888
+ var features = state.features;
42889
+ if ((jsonContent === null || jsonContent === void 0 ? void 0 : jsonContent.type) !== "module") {
42890
+ state.features &= ~NodeResolutionFeatures.EsmMode;
42891
+ }
42892
+ var result = nodeLoadModuleByRelativeName(nextExtensions, candidate, onlyRecordFailures, state, /*considerPackageJson*/ false);
42893
+ state.features = features;
42894
+ return result;
42832
42895
  };
42833
42896
  var onlyRecordFailuresForPackageFile = packageFile ? !ts.directoryProbablyExists(ts.getDirectoryPath(packageFile), state.host) : undefined;
42834
42897
  var onlyRecordFailuresForIndex = onlyRecordFailures || !ts.directoryProbablyExists(candidate, state.host);
@@ -43173,6 +43236,14 @@ var ts;
43173
43236
  }
43174
43237
  var pathAndExtension = loadModuleFromFile(extensions, candidate, onlyRecordFailures, state) ||
43175
43238
  loadNodeModuleFromDirectoryWorker(extensions, candidate, onlyRecordFailures, state, packageInfo && packageInfo.packageJsonContent, packageInfo && packageInfo.versionPaths);
43239
+ if (!pathAndExtension && packageInfo
43240
+ && packageInfo.packageJsonContent.exports === undefined
43241
+ && packageInfo.packageJsonContent.main === undefined
43242
+ && state.features & NodeResolutionFeatures.EsmMode) {
43243
+ // EsmMode disables index lookup in `loadNodeModuleFromDirectoryWorker` generally, however non-relative package resolutions still assume
43244
+ // a default `index.js` entrypoint if no `main` or `exports` are present
43245
+ pathAndExtension = loadModuleFromFile(extensions, ts.combinePaths(candidate, "index.js"), onlyRecordFailures, state);
43246
+ }
43176
43247
  return withPackageId(packageInfo, pathAndExtension);
43177
43248
  };
43178
43249
  if (rest !== "") { // If "rest" is empty, we just did this search above.
@@ -46930,8 +47001,7 @@ var ts;
46930
47001
  IntersectionState[IntersectionState["Source"] = 1] = "Source";
46931
47002
  IntersectionState[IntersectionState["Target"] = 2] = "Target";
46932
47003
  IntersectionState[IntersectionState["PropertyCheck"] = 4] = "PropertyCheck";
46933
- IntersectionState[IntersectionState["UnionIntersectionCheck"] = 8] = "UnionIntersectionCheck";
46934
- IntersectionState[IntersectionState["InPropertyCheck"] = 16] = "InPropertyCheck";
47004
+ IntersectionState[IntersectionState["InPropertyCheck"] = 8] = "InPropertyCheck";
46935
47005
  })(IntersectionState || (IntersectionState = {}));
46936
47006
  var RecursionFlags;
46937
47007
  (function (RecursionFlags) {
@@ -50390,8 +50460,15 @@ var ts;
50390
50460
  return res;
50391
50461
  }
50392
50462
  var candidates = ts.mapDefined(symbol.declarations, function (d) {
50393
- if (!ts.isAmbientModule(d) && d.parent && hasNonGlobalAugmentationExternalModuleSymbol(d.parent)) {
50394
- return getSymbolOfNode(d.parent);
50463
+ if (!ts.isAmbientModule(d) && d.parent) {
50464
+ // direct children of a module
50465
+ if (hasNonGlobalAugmentationExternalModuleSymbol(d.parent)) {
50466
+ return getSymbolOfNode(d.parent);
50467
+ }
50468
+ // export ='d member of an ambient module
50469
+ if (ts.isModuleBlock(d.parent) && d.parent.parent && resolveExternalModuleSymbol(getSymbolOfNode(d.parent.parent)) === symbol) {
50470
+ return getSymbolOfNode(d.parent.parent);
50471
+ }
50395
50472
  }
50396
50473
  if (ts.isClassExpression(d) && ts.isBinaryExpression(d.parent) && d.parent.operatorToken.kind === 63 /* EqualsToken */ && ts.isAccessExpression(d.parent.left) && ts.isEntityNameExpression(d.parent.left.expression)) {
50397
50474
  if (ts.isModuleExportsAccessExpression(d.parent.left) || ts.isExportsIdentifier(d.parent.left.expression)) {
@@ -50938,7 +51015,7 @@ var ts;
50938
51015
  // get symbol of the first identifier of the entityName
50939
51016
  var meaning;
50940
51017
  if (entityName.parent.kind === 180 /* TypeQuery */ ||
50941
- ts.isExpressionWithTypeArgumentsInClassExtendsClause(entityName.parent) ||
51018
+ entityName.parent.kind === 227 /* ExpressionWithTypeArguments */ && !ts.isPartOfTypeNode(entityName.parent) ||
50942
51019
  entityName.parent.kind === 161 /* ComputedPropertyName */) {
50943
51020
  // Typeof value
50944
51021
  meaning = 111551 /* Value */ | 1048576 /* ExportValue */;
@@ -51049,7 +51126,7 @@ var ts;
51049
51126
  return flags & 814775659 /* NodeBuilderFlagsMask */;
51050
51127
  }
51051
51128
  function isClassInstanceSide(type) {
51052
- return !!type.symbol && !!(type.symbol.flags & 32 /* Class */) && (type === getDeclaredTypeOfClassOrInterface(type.symbol) || (!!(type.flags & 524288 /* Object */) && !!(ts.getObjectFlags(type) & 16777216 /* IsClassInstanceClone */)));
51129
+ return !!type.symbol && !!(type.symbol.flags & 32 /* Class */) && (type === getDeclaredTypeOfClassOrInterface(type.symbol) || (!!(type.flags & 524288 /* Object */) && !!(ts.getObjectFlags(type) & 33554432 /* IsClassInstanceClone */)));
51053
51130
  }
51054
51131
  function createNodeBuilder() {
51055
51132
  return {
@@ -54978,7 +55055,7 @@ var ts;
54978
55055
  members_4, exportedType.callSignatures, exportedType.constructSignatures, exportedType.indexInfos);
54979
55056
  result.objectFlags |= (ts.getObjectFlags(type) & 8192 /* JSLiteral */); // Propagate JSLiteral flag
54980
55057
  if (result.symbol && result.symbol.flags & 32 /* Class */ && type === getDeclaredTypeOfClassOrInterface(result.symbol)) {
54981
- result.objectFlags |= 16777216 /* IsClassInstanceClone */; // Propagate the knowledge that this type is equivalent to the symbol's class instance type
55058
+ result.objectFlags |= 33554432 /* IsClassInstanceClone */; // Propagate the knowledge that this type is equivalent to the symbol's class instance type
54982
55059
  }
54983
55060
  return result;
54984
55061
  }
@@ -57024,87 +57101,87 @@ var ts;
57024
57101
  * Converts an AnonymousType to a ResolvedType.
57025
57102
  */
57026
57103
  function resolveAnonymousTypeMembers(type) {
57027
- var symbol = getMergedSymbol(type.symbol);
57028
57104
  if (type.target) {
57029
57105
  setStructuredTypeMembers(type, emptySymbols, ts.emptyArray, ts.emptyArray, ts.emptyArray);
57030
- var members = createInstantiatedSymbolTable(getPropertiesOfObjectType(type.target), type.mapper, /*mappingThisOnly*/ false);
57106
+ var members_6 = createInstantiatedSymbolTable(getPropertiesOfObjectType(type.target), type.mapper, /*mappingThisOnly*/ false);
57031
57107
  var callSignatures = instantiateSignatures(getSignaturesOfType(type.target, 0 /* Call */), type.mapper);
57032
57108
  var constructSignatures = instantiateSignatures(getSignaturesOfType(type.target, 1 /* Construct */), type.mapper);
57033
- var indexInfos = instantiateIndexInfos(getIndexInfosOfType(type.target), type.mapper);
57034
- setStructuredTypeMembers(type, members, callSignatures, constructSignatures, indexInfos);
57109
+ var indexInfos_1 = instantiateIndexInfos(getIndexInfosOfType(type.target), type.mapper);
57110
+ setStructuredTypeMembers(type, members_6, callSignatures, constructSignatures, indexInfos_1);
57111
+ return;
57035
57112
  }
57036
- else if (symbol.flags & 2048 /* TypeLiteral */) {
57113
+ var symbol = getMergedSymbol(type.symbol);
57114
+ if (symbol.flags & 2048 /* TypeLiteral */) {
57037
57115
  setStructuredTypeMembers(type, emptySymbols, ts.emptyArray, ts.emptyArray, ts.emptyArray);
57038
- var members = getMembersOfSymbol(symbol);
57039
- var callSignatures = getSignaturesOfSymbol(members.get("__call" /* Call */));
57040
- var constructSignatures = getSignaturesOfSymbol(members.get("__new" /* New */));
57041
- var indexInfos = getIndexInfosOfSymbol(symbol);
57042
- setStructuredTypeMembers(type, members, callSignatures, constructSignatures, indexInfos);
57116
+ var members_7 = getMembersOfSymbol(symbol);
57117
+ var callSignatures = getSignaturesOfSymbol(members_7.get("__call" /* Call */));
57118
+ var constructSignatures = getSignaturesOfSymbol(members_7.get("__new" /* New */));
57119
+ var indexInfos_2 = getIndexInfosOfSymbol(symbol);
57120
+ setStructuredTypeMembers(type, members_7, callSignatures, constructSignatures, indexInfos_2);
57121
+ return;
57043
57122
  }
57044
- else {
57045
- // Combinations of function, class, enum and module
57046
- var members = emptySymbols;
57047
- var indexInfos = void 0;
57048
- if (symbol.exports) {
57049
- members = getExportsOfSymbol(symbol);
57050
- if (symbol === globalThisSymbol) {
57051
- var varsOnly_1 = new ts.Map();
57052
- members.forEach(function (p) {
57053
- if (!(p.flags & 418 /* BlockScoped */)) {
57054
- varsOnly_1.set(p.escapedName, p);
57055
- }
57056
- });
57057
- members = varsOnly_1;
57058
- }
57123
+ // Combinations of function, class, enum and module
57124
+ var members = emptySymbols;
57125
+ var indexInfos;
57126
+ if (symbol.exports) {
57127
+ members = getExportsOfSymbol(symbol);
57128
+ if (symbol === globalThisSymbol) {
57129
+ var varsOnly_1 = new ts.Map();
57130
+ members.forEach(function (p) {
57131
+ if (!(p.flags & 418 /* BlockScoped */)) {
57132
+ varsOnly_1.set(p.escapedName, p);
57133
+ }
57134
+ });
57135
+ members = varsOnly_1;
57059
57136
  }
57060
- var baseConstructorIndexInfo = void 0;
57061
- setStructuredTypeMembers(type, members, ts.emptyArray, ts.emptyArray, ts.emptyArray);
57062
- if (symbol.flags & 32 /* Class */) {
57063
- var classType = getDeclaredTypeOfClassOrInterface(symbol);
57064
- var baseConstructorType = getBaseConstructorTypeOfClass(classType);
57065
- if (baseConstructorType.flags & (524288 /* Object */ | 2097152 /* Intersection */ | 8650752 /* TypeVariable */)) {
57066
- members = ts.createSymbolTable(getNamedOrIndexSignatureMembers(members));
57067
- addInheritedMembers(members, getPropertiesOfType(baseConstructorType));
57068
- }
57069
- else if (baseConstructorType === anyType) {
57070
- baseConstructorIndexInfo = createIndexInfo(stringType, anyType, /*isReadonly*/ false);
57071
- }
57137
+ }
57138
+ var baseConstructorIndexInfo;
57139
+ setStructuredTypeMembers(type, members, ts.emptyArray, ts.emptyArray, ts.emptyArray);
57140
+ if (symbol.flags & 32 /* Class */) {
57141
+ var classType = getDeclaredTypeOfClassOrInterface(symbol);
57142
+ var baseConstructorType = getBaseConstructorTypeOfClass(classType);
57143
+ if (baseConstructorType.flags & (524288 /* Object */ | 2097152 /* Intersection */ | 8650752 /* TypeVariable */)) {
57144
+ members = ts.createSymbolTable(getNamedOrIndexSignatureMembers(members));
57145
+ addInheritedMembers(members, getPropertiesOfType(baseConstructorType));
57072
57146
  }
57073
- var indexSymbol = getIndexSymbolFromSymbolTable(members);
57074
- if (indexSymbol) {
57075
- indexInfos = getIndexInfosOfIndexSymbol(indexSymbol);
57147
+ else if (baseConstructorType === anyType) {
57148
+ baseConstructorIndexInfo = createIndexInfo(stringType, anyType, /*isReadonly*/ false);
57076
57149
  }
57077
- else {
57078
- if (baseConstructorIndexInfo) {
57079
- indexInfos = ts.append(indexInfos, baseConstructorIndexInfo);
57080
- }
57081
- if (symbol.flags & 384 /* Enum */ && (getDeclaredTypeOfSymbol(symbol).flags & 32 /* Enum */ ||
57082
- ts.some(type.properties, function (prop) { return !!(getTypeOfSymbol(prop).flags & 296 /* NumberLike */); }))) {
57083
- indexInfos = ts.append(indexInfos, enumNumberIndexInfo);
57084
- }
57150
+ }
57151
+ var indexSymbol = getIndexSymbolFromSymbolTable(members);
57152
+ if (indexSymbol) {
57153
+ indexInfos = getIndexInfosOfIndexSymbol(indexSymbol);
57154
+ }
57155
+ else {
57156
+ if (baseConstructorIndexInfo) {
57157
+ indexInfos = ts.append(indexInfos, baseConstructorIndexInfo);
57085
57158
  }
57086
- setStructuredTypeMembers(type, members, ts.emptyArray, ts.emptyArray, indexInfos || ts.emptyArray);
57087
- // We resolve the members before computing the signatures because a signature may use
57088
- // typeof with a qualified name expression that circularly references the type we are
57089
- // in the process of resolving (see issue #6072). The temporarily empty signature list
57090
- // will never be observed because a qualified name can't reference signatures.
57091
- if (symbol.flags & (16 /* Function */ | 8192 /* Method */)) {
57092
- type.callSignatures = getSignaturesOfSymbol(symbol);
57159
+ if (symbol.flags & 384 /* Enum */ && (getDeclaredTypeOfSymbol(symbol).flags & 32 /* Enum */ ||
57160
+ ts.some(type.properties, function (prop) { return !!(getTypeOfSymbol(prop).flags & 296 /* NumberLike */); }))) {
57161
+ indexInfos = ts.append(indexInfos, enumNumberIndexInfo);
57093
57162
  }
57094
- // And likewise for construct signatures for classes
57095
- if (symbol.flags & 32 /* Class */) {
57096
- var classType_1 = getDeclaredTypeOfClassOrInterface(symbol);
57097
- var constructSignatures = symbol.members ? getSignaturesOfSymbol(symbol.members.get("__constructor" /* Constructor */)) : ts.emptyArray;
57098
- if (symbol.flags & 16 /* Function */) {
57099
- constructSignatures = ts.addRange(constructSignatures.slice(), ts.mapDefined(type.callSignatures, function (sig) { return isJSConstructor(sig.declaration) ?
57100
- createSignature(sig.declaration, sig.typeParameters, sig.thisParameter, sig.parameters, classType_1, /*resolvedTypePredicate*/ undefined, sig.minArgumentCount, sig.flags & 39 /* PropagatingFlags */) :
57101
- undefined; }));
57102
- }
57103
- if (!constructSignatures.length) {
57104
- constructSignatures = getDefaultConstructSignatures(classType_1);
57105
- }
57106
- type.constructSignatures = constructSignatures;
57163
+ }
57164
+ setStructuredTypeMembers(type, members, ts.emptyArray, ts.emptyArray, indexInfos || ts.emptyArray);
57165
+ // We resolve the members before computing the signatures because a signature may use
57166
+ // typeof with a qualified name expression that circularly references the type we are
57167
+ // in the process of resolving (see issue #6072). The temporarily empty signature list
57168
+ // will never be observed because a qualified name can't reference signatures.
57169
+ if (symbol.flags & (16 /* Function */ | 8192 /* Method */)) {
57170
+ type.callSignatures = getSignaturesOfSymbol(symbol);
57171
+ }
57172
+ // And likewise for construct signatures for classes
57173
+ if (symbol.flags & 32 /* Class */) {
57174
+ var classType_1 = getDeclaredTypeOfClassOrInterface(symbol);
57175
+ var constructSignatures = symbol.members ? getSignaturesOfSymbol(symbol.members.get("__constructor" /* Constructor */)) : ts.emptyArray;
57176
+ if (symbol.flags & 16 /* Function */) {
57177
+ constructSignatures = ts.addRange(constructSignatures.slice(), ts.mapDefined(type.callSignatures, function (sig) { return isJSConstructor(sig.declaration) ?
57178
+ createSignature(sig.declaration, sig.typeParameters, sig.thisParameter, sig.parameters, classType_1, /*resolvedTypePredicate*/ undefined, sig.minArgumentCount, sig.flags & 39 /* PropagatingFlags */) :
57179
+ undefined; }));
57107
57180
  }
57181
+ if (!constructSignatures.length) {
57182
+ constructSignatures = getDefaultConstructSignatures(classType_1);
57183
+ }
57184
+ type.constructSignatures = constructSignatures;
57108
57185
  }
57109
57186
  }
57110
57187
  function replaceIndexedAccess(instantiable, type, replacement) {
@@ -58105,8 +58182,8 @@ var ts;
58105
58182
  var stringIndexInfo;
58106
58183
  var applicableInfo;
58107
58184
  var applicableInfos;
58108
- for (var _i = 0, indexInfos_1 = indexInfos; _i < indexInfos_1.length; _i++) {
58109
- var info = indexInfos_1[_i];
58185
+ for (var _i = 0, indexInfos_3 = indexInfos; _i < indexInfos_3.length; _i++) {
58186
+ var info = indexInfos_3[_i];
58110
58187
  if (info.keyType === stringType) {
58111
58188
  stringIndexInfo = info;
58112
58189
  }
@@ -58645,13 +58722,15 @@ var ts;
58645
58722
  return signature;
58646
58723
  }
58647
58724
  function getOrCreateTypeFromSignature(signature) {
58725
+ var _a;
58648
58726
  // There are two ways to declare a construct signature, one is by declaring a class constructor
58649
58727
  // using the constructor keyword, and the other is declaring a bare construct signature in an
58650
58728
  // object type literal or interface (using the new keyword). Each way of declaring a constructor
58651
58729
  // will result in a different declaration kind.
58652
58730
  if (!signature.isolatedSignatureType) {
58653
- var kind = signature.declaration ? signature.declaration.kind : 0 /* Unknown */;
58654
- var isConstructor = kind === 170 /* Constructor */ || kind === 174 /* ConstructSignature */ || kind === 179 /* ConstructorType */;
58731
+ var kind = (_a = signature.declaration) === null || _a === void 0 ? void 0 : _a.kind;
58732
+ // If declaration is undefined, it is likely to be the signature of the default constructor.
58733
+ var isConstructor = kind === undefined || kind === 170 /* Constructor */ || kind === 174 /* ConstructSignature */ || kind === 179 /* ConstructorType */;
58655
58734
  var type = createObjectType(16 /* Anonymous */);
58656
58735
  type.members = emptySymbols;
58657
58736
  type.properties = ts.emptyArray;
@@ -58677,14 +58756,14 @@ var ts;
58677
58756
  }
58678
58757
  function getIndexInfosOfIndexSymbol(indexSymbol) {
58679
58758
  if (indexSymbol.declarations) {
58680
- var indexInfos_2 = [];
58759
+ var indexInfos_4 = [];
58681
58760
  var _loop_14 = function (declaration) {
58682
58761
  if (declaration.parameters.length === 1) {
58683
58762
  var parameter = declaration.parameters[0];
58684
58763
  if (parameter.type) {
58685
58764
  forEachType(getTypeFromTypeNode(parameter.type), function (keyType) {
58686
- if (isValidIndexKeyType(keyType) && !findIndexInfo(indexInfos_2, keyType)) {
58687
- indexInfos_2.push(createIndexInfo(keyType, declaration.type ? getTypeFromTypeNode(declaration.type) : anyType, ts.hasEffectiveModifier(declaration, 64 /* Readonly */), declaration));
58765
+ if (isValidIndexKeyType(keyType) && !findIndexInfo(indexInfos_4, keyType)) {
58766
+ indexInfos_4.push(createIndexInfo(keyType, declaration.type ? getTypeFromTypeNode(declaration.type) : anyType, ts.hasEffectiveModifier(declaration, 64 /* Readonly */), declaration));
58688
58767
  }
58689
58768
  });
58690
58769
  }
@@ -58694,7 +58773,7 @@ var ts;
58694
58773
  var declaration = _a[_i];
58695
58774
  _loop_14(declaration);
58696
58775
  }
58697
- return indexInfos_2;
58776
+ return indexInfos_4;
58698
58777
  }
58699
58778
  return ts.emptyArray;
58700
58779
  }
@@ -59242,7 +59321,7 @@ var ts;
59242
59321
  // The expression is processed as an identifier expression (section 4.3)
59243
59322
  // or property access expression(section 4.10),
59244
59323
  // the widened type(section 3.9) of which becomes the result.
59245
- var type = ts.isThisIdentifier(node.exprName) ? checkThisExpression(node.exprName) : checkExpression(node.exprName);
59324
+ var type = checkExpressionWithTypeArguments(node);
59246
59325
  links.resolvedType = getRegularTypeOfLiteralType(getWidenedType(type));
59247
59326
  }
59248
59327
  return links.resolvedType;
@@ -59579,7 +59658,7 @@ var ts;
59579
59658
  }
59580
59659
  }
59581
59660
  var fixedLength = properties.length;
59582
- var lengthSymbol = createSymbol(4 /* Property */, "length");
59661
+ var lengthSymbol = createSymbol(4 /* Property */, "length", readonly ? 8 /* Readonly */ : 0);
59583
59662
  if (combinedFlags & 12 /* Variable */) {
59584
59663
  lengthSymbol.type = numberType;
59585
59664
  }
@@ -61946,7 +62025,9 @@ var ts;
61946
62025
  return result;
61947
62026
  }
61948
62027
  function getObjectTypeInstantiation(type, mapper, aliasSymbol, aliasTypeArguments) {
61949
- var declaration = type.objectFlags & 4 /* Reference */ ? type.node : type.symbol.declarations[0];
62028
+ var declaration = type.objectFlags & 4 /* Reference */ ? type.node :
62029
+ type.objectFlags & 16777216 /* InstantiationExpressionType */ ? type.node :
62030
+ type.symbol.declarations[0];
61950
62031
  var links = getNodeLinks(declaration);
61951
62032
  var target = type.objectFlags & 4 /* Reference */ ? links.resolvedType :
61952
62033
  type.objectFlags & 64 /* Instantiated */ ? type.target : type;
@@ -61962,8 +62043,8 @@ var ts;
61962
62043
  outerTypeParameters = ts.addRange(outerTypeParameters, templateTagParameters);
61963
62044
  }
61964
62045
  typeParameters = outerTypeParameters || ts.emptyArray;
61965
- var allDeclarations_1 = type.objectFlags & 4 /* Reference */ ? [declaration] : type.symbol.declarations;
61966
- typeParameters = (target.objectFlags & 4 /* Reference */ || target.symbol.flags & 8192 /* Method */ || target.symbol.flags & 2048 /* TypeLiteral */) && !target.aliasTypeArguments ?
62046
+ var allDeclarations_1 = type.objectFlags & (4 /* Reference */ | 16777216 /* InstantiationExpressionType */) ? [declaration] : type.symbol.declarations;
62047
+ typeParameters = (target.objectFlags & (4 /* Reference */ | 16777216 /* InstantiationExpressionType */) || target.symbol.flags & 8192 /* Method */ || target.symbol.flags & 2048 /* TypeLiteral */) && !target.aliasTypeArguments ?
61967
62048
  ts.filter(typeParameters, function (tp) { return ts.some(allDeclarations_1, function (d) { return isTypeParameterPossiblyReferenced(tp, d); }); }) :
61968
62049
  typeParameters;
61969
62050
  links.outerTypeParameters = typeParameters;
@@ -62135,6 +62216,9 @@ var ts;
62135
62216
  mapper = combineTypeMappers(makeUnaryTypeMapper(origTypeParameter, freshTypeParameter), mapper);
62136
62217
  freshTypeParameter.mapper = mapper;
62137
62218
  }
62219
+ if (type.objectFlags & 16777216 /* InstantiationExpressionType */) {
62220
+ result.node = type.node;
62221
+ }
62138
62222
  result.target = type;
62139
62223
  result.mapper = mapper;
62140
62224
  result.aliasSymbol = aliasSymbol || type.aliasSymbol;
@@ -63126,9 +63210,11 @@ var ts;
63126
63210
  isEnumTypeRelatedTo(getParentOfSymbol(source.symbol), getParentOfSymbol(target.symbol), errorReporter))
63127
63211
  return true;
63128
63212
  }
63129
- if (s & 32768 /* Undefined */ && (!strictNullChecks || t & (32768 /* Undefined */ | 16384 /* Void */)))
63213
+ // In non-strictNullChecks mode, `undefined` and `null` are assignable to anything except `never`.
63214
+ // Since unions and intersections may reduce to `never`, we exclude them here.
63215
+ if (s & 32768 /* Undefined */ && (!strictNullChecks && !(t & 3145728 /* UnionOrIntersection */) || t & (32768 /* Undefined */ | 16384 /* Void */)))
63130
63216
  return true;
63131
- if (s & 65536 /* Null */ && (!strictNullChecks || t & 65536 /* Null */))
63217
+ if (s & 65536 /* Null */ && (!strictNullChecks && !(t & 3145728 /* UnionOrIntersection */) || t & 65536 /* Null */))
63132
63218
  return true;
63133
63219
  if (s & 524288 /* Object */ && t & 67108864 /* NonPrimitive */)
63134
63220
  return true;
@@ -63217,11 +63303,11 @@ var ts;
63217
63303
  var overflow = false;
63218
63304
  var overrideNextErrorInfo = 0; // How many `reportRelationError` calls should be skipped in the elaboration pyramid
63219
63305
  var lastSkippedInfo;
63220
- var incompatibleStack = [];
63306
+ var incompatibleStack;
63221
63307
  var inPropertyCheck = false;
63222
63308
  ts.Debug.assert(relation !== identityRelation || !errorNode, "no error reporting in identity checking");
63223
63309
  var result = isRelatedTo(source, target, 3 /* Both */, /*reportErrors*/ !!errorNode, headMessage);
63224
- if (incompatibleStack.length) {
63310
+ if (incompatibleStack) {
63225
63311
  reportIncompatibleStack();
63226
63312
  }
63227
63313
  if (overflow) {
@@ -63278,19 +63364,19 @@ var ts;
63278
63364
  return {
63279
63365
  errorInfo: errorInfo,
63280
63366
  lastSkippedInfo: lastSkippedInfo,
63281
- incompatibleStack: incompatibleStack.slice(),
63367
+ incompatibleStack: incompatibleStack === null || incompatibleStack === void 0 ? void 0 : incompatibleStack.slice(),
63282
63368
  overrideNextErrorInfo: overrideNextErrorInfo,
63283
- relatedInfo: !relatedInfo ? undefined : relatedInfo.slice()
63369
+ relatedInfo: relatedInfo === null || relatedInfo === void 0 ? void 0 : relatedInfo.slice(),
63284
63370
  };
63285
63371
  }
63286
63372
  function reportIncompatibleError(message, arg0, arg1, arg2, arg3) {
63287
63373
  overrideNextErrorInfo++; // Suppress the next relation error
63288
63374
  lastSkippedInfo = undefined; // Reset skipped info cache
63289
- incompatibleStack.push([message, arg0, arg1, arg2, arg3]);
63375
+ (incompatibleStack || (incompatibleStack = [])).push([message, arg0, arg1, arg2, arg3]);
63290
63376
  }
63291
63377
  function reportIncompatibleStack() {
63292
- var stack = incompatibleStack;
63293
- incompatibleStack = [];
63378
+ var stack = incompatibleStack || [];
63379
+ incompatibleStack = undefined;
63294
63380
  var info = lastSkippedInfo;
63295
63381
  lastSkippedInfo = undefined;
63296
63382
  if (stack.length === 1) {
@@ -63396,7 +63482,7 @@ var ts;
63396
63482
  }
63397
63483
  function reportError(message, arg0, arg1, arg2, arg3) {
63398
63484
  ts.Debug.assert(!!errorNode);
63399
- if (incompatibleStack.length)
63485
+ if (incompatibleStack)
63400
63486
  reportIncompatibleStack();
63401
63487
  if (message.elidedInCompatabilityPyramid)
63402
63488
  return;
@@ -63412,7 +63498,7 @@ var ts;
63412
63498
  }
63413
63499
  }
63414
63500
  function reportRelationError(message, source, target) {
63415
- if (incompatibleStack.length)
63501
+ if (incompatibleStack)
63416
63502
  reportIncompatibleStack();
63417
63503
  var _a = getTypeNamesForErrorDisplay(source, target), sourceType = _a[0], targetType = _a[1];
63418
63504
  var generalizedSource = source;
@@ -63524,7 +63610,9 @@ var ts;
63524
63610
  if (isSimpleTypeRelatedTo(originalSource, originalTarget, relation, reportErrors ? reportError : undefined)) {
63525
63611
  return -1 /* True */;
63526
63612
  }
63527
- reportErrorResults(originalSource, originalTarget, 0 /* False */, !!(ts.getObjectFlags(originalSource) & 2048 /* JsxAttributes */));
63613
+ if (reportErrors) {
63614
+ reportErrorResults(originalSource, originalTarget, originalSource, originalTarget, headMessage);
63615
+ }
63528
63616
  return 0 /* False */;
63529
63617
  }
63530
63618
  // Normalize the source and target types: Turn fresh literal types into regular literal types,
@@ -63536,7 +63624,12 @@ var ts;
63536
63624
  if (source === target)
63537
63625
  return -1 /* True */;
63538
63626
  if (relation === identityRelation) {
63539
- 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);
63540
63633
  }
63541
63634
  // We fastpath comparing a type parameter to exactly its constraint, as this is _super_ common,
63542
63635
  // and otherwise, for type parameters in large unions, causes us to need to compare the union to itself,
@@ -63546,163 +63639,130 @@ var ts;
63546
63639
  if (source.flags & 262144 /* TypeParameter */ && getConstraintOfType(source) === target) {
63547
63640
  return -1 /* True */;
63548
63641
  }
63549
- // Try to see if we're relating something like `Foo` -> `Bar | null | undefined`.
63550
- // If so, reporting the `null` and `undefined` in the type is hardly useful.
63551
- // First, see if we're even relating an object type to a union.
63552
- // Then see if the target is stripped down to a single non-union type.
63553
- // Note
63554
- // * We actually want to remove null and undefined naively here (rather than using getNonNullableType),
63555
- // since we don't want to end up with a worse error like "`Foo` is not assignable to `NonNullable<T>`"
63556
- // when dealing with generics.
63557
- // * We also don't deal with primitive source types, since we already halt elaboration below.
63558
- if (target.flags & 1048576 /* Union */ && source.flags & 524288 /* Object */ &&
63559
- target.types.length <= 3 && maybeTypeOfKind(target, 98304 /* Nullable */)) {
63560
- var nullStrippedTarget = extractTypesOfKind(target, ~98304 /* Nullable */);
63561
- if (!(nullStrippedTarget.flags & (1048576 /* Union */ | 131072 /* Never */))) {
63562
- target = getNormalizedType(nullStrippedTarget, /*writing*/ true);
63563
- }
63564
- if (source === nullStrippedTarget)
63565
- 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
+ }
63566
63654
  }
63567
63655
  if (relation === comparableRelation && !(target.flags & 131072 /* Never */) && isSimpleTypeRelatedTo(target, source, relation) ||
63568
63656
  isSimpleTypeRelatedTo(source, target, relation, reportErrors ? reportError : undefined))
63569
63657
  return -1 /* True */;
63570
- var isComparingJsxAttributes = !!(ts.getObjectFlags(source) & 2048 /* JsxAttributes */);
63571
- var isPerformingExcessPropertyChecks = !(intersectionState & 2 /* Target */) && (isObjectLiteralType(source) && ts.getObjectFlags(source) & 16384 /* FreshLiteral */);
63572
- if (isPerformingExcessPropertyChecks) {
63573
- 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)) {
63574
63674
  if (reportErrors) {
63575
- 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
+ }
63576
63686
  }
63577
63687
  return 0 /* False */;
63578
63688
  }
63579
- }
63580
- var isPerformingCommonPropertyChecks = relation !== comparableRelation && !(intersectionState & 2 /* Target */) &&
63581
- source.flags & (131068 /* Primitive */ | 524288 /* Object */ | 2097152 /* Intersection */) && source !== globalObjectType &&
63582
- target.flags & (524288 /* Object */ | 2097152 /* Intersection */) && isWeakType(target) &&
63583
- (getPropertiesOfType(source).length > 0 || typeHasCallOrConstructSignatures(source));
63584
- if (isPerformingCommonPropertyChecks && !hasCommonProperties(source, target, isComparingJsxAttributes)) {
63585
- if (reportErrors) {
63586
- var sourceString = typeToString(originalSource.aliasSymbol ? originalSource : source);
63587
- var targetString = typeToString(originalTarget.aliasSymbol ? originalTarget : target);
63588
- var calls = getSignaturesOfType(source, 0 /* Call */);
63589
- var constructs = getSignaturesOfType(source, 1 /* Construct */);
63590
- if (calls.length > 0 && isRelatedTo(getReturnTypeOfSignature(calls[0]), target, 1 /* Source */, /*reportErrors*/ false) ||
63591
- constructs.length > 0 && isRelatedTo(getReturnTypeOfSignature(constructs[0]), target, 1 /* Source */, /*reportErrors*/ false)) {
63592
- reportError(ts.Diagnostics.Value_of_type_0_has_no_properties_in_common_with_type_1_Did_you_mean_to_call_it, sourceString, targetString);
63593
- }
63594
- else {
63595
- reportError(ts.Diagnostics.Type_0_has_no_properties_in_common_with_type_1, sourceString, targetString);
63596
- }
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;
63597
63718
  }
63598
- return 0 /* False */;
63599
- }
63600
- traceUnionsOrIntersectionsTooLarge(source, target);
63601
- var result = 0 /* False */;
63602
- var saveErrorInfo = captureErrorCalculationState();
63603
- if ((source.flags & 1048576 /* Union */ || target.flags & 1048576 /* Union */) && getConstituentCount(source) * getConstituentCount(target) < 4) {
63604
- // We skip caching when source or target is a union with no more than three constituents.
63605
- result = structuredTypeRelatedTo(source, target, reportErrors, intersectionState | 8 /* UnionIntersectionCheck */);
63606
63719
  }
63607
- else if (source.flags & 3145728 /* UnionOrIntersection */ || target.flags & 3145728 /* UnionOrIntersection */) {
63608
- result = recursiveTypeRelatedTo(source, target, reportErrors, intersectionState | 8 /* UnionIntersectionCheck */, recursionFlags);
63720
+ if (reportErrors) {
63721
+ reportErrorResults(originalSource, originalTarget, source, target, headMessage);
63609
63722
  }
63610
- if (!result && !(source.flags & 1048576 /* Union */) && (source.flags & (469499904 /* StructuredOrInstantiable */) || target.flags & 469499904 /* StructuredOrInstantiable */)) {
63611
- if (result = recursiveTypeRelatedTo(source, target, reportErrors, intersectionState, recursionFlags)) {
63612
- 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;
63613
63755
  }
63614
63756
  }
63615
- if (!result && source.flags & (2097152 /* Intersection */ | 262144 /* TypeParameter */)) {
63616
- // The combined constraint of an intersection type is the intersection of the constraints of
63617
- // the constituents. When an intersection type contains instantiable types with union type
63618
- // constraints, there are situations where we need to examine the combined constraint. One is
63619
- // when the target is a union type. Another is when the intersection contains types belonging
63620
- // to one of the disjoint domains. For example, given type variables T and U, each with the
63621
- // constraint 'string | number', the combined constraint of 'T & U' is 'string | number' and
63622
- // we need to check this constraint against a union on the target side. Also, given a type
63623
- // variable V constrained to 'string | number', 'V & number' has a combined constraint of
63624
- // 'string & number | number & number' which reduces to just 'number'.
63625
- // This also handles type parameters, as a type parameter with a union constraint compared against a union
63626
- // needs to have its constraint hoisted into an intersection with said type parameter, this way
63627
- // the type param can be compared with itself in the target (with the influence of its constraint to match other parts)
63628
- // For example, if `T extends 1 | 2` and `U extends 2 | 3` and we compare `T & U` to `T & U & (1 | 2 | 3)`
63629
- var constraint = getEffectiveConstraintOfIntersection(source.flags & 2097152 /* Intersection */ ? source.types : [source], !!(target.flags & 1048576 /* Union */));
63630
- if (constraint && (source.flags & 2097152 /* Intersection */ || target.flags & 1048576 /* Union */)) {
63631
- if (everyType(constraint, function (c) { return c !== source; })) { // Skip comparison if expansion contains the source itself
63632
- // TODO: Stack errors so we get a pyramid for the "normal" comparison above, _and_ a second for this
63633
- if (result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
63634
- resetErrorInfo(saveErrorInfo);
63635
- }
63636
- }
63637
- }
63757
+ else {
63758
+ errorInfo = elaborateNeverIntersection(errorInfo, originalTarget);
63638
63759
  }
63639
- // For certain combinations involving intersections and optional, excess, or mismatched properties we need
63640
- // an extra property check where the intersection is viewed as a single object. The following are motivating
63641
- // examples that all should be errors, but aren't without this extra property check:
63642
- //
63643
- // let obj: { a: { x: string } } & { c: number } = { a: { x: 'hello', y: 2 }, c: 5 }; // Nested excess property
63644
- //
63645
- // declare let wrong: { a: { y: string } };
63646
- // let weak: { a?: { x?: number } } & { c?: string } = wrong; // Nested weak object type
63647
- //
63648
- // function foo<T extends object>(x: { a?: string }, y: T & { a: boolean }) {
63649
- // x = y; // Mismatched property in source intersection
63650
- // }
63651
- //
63652
- // We suppress recursive intersection property checks because they can generate lots of work when relating
63653
- // recursive intersections that are structurally similar but not exactly identical. See #37854.
63654
- if (result && !inPropertyCheck && (target.flags & 2097152 /* Intersection */ && (isPerformingExcessPropertyChecks || isPerformingCommonPropertyChecks) ||
63655
- 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 */); }))) {
63656
- inPropertyCheck = true;
63657
- result &= recursiveTypeRelatedTo(source, target, reportErrors, 4 /* PropertyCheck */, recursionFlags);
63658
- inPropertyCheck = false;
63659
- }
63660
- reportErrorResults(source, target, result, isComparingJsxAttributes);
63661
- return result;
63662
- function reportErrorResults(source, target, result, isComparingJsxAttributes) {
63663
- if (!result && reportErrors) {
63664
- var sourceHasBase = !!getSingleBaseForNonAugmentingSubtype(originalSource);
63665
- var targetHasBase = !!getSingleBaseForNonAugmentingSubtype(originalTarget);
63666
- source = (originalSource.aliasSymbol || sourceHasBase) ? originalSource : source;
63667
- target = (originalTarget.aliasSymbol || targetHasBase) ? originalTarget : target;
63668
- var maybeSuppress = overrideNextErrorInfo > 0;
63669
- if (maybeSuppress) {
63670
- overrideNextErrorInfo--;
63671
- }
63672
- if (source.flags & 524288 /* Object */ && target.flags & 524288 /* Object */) {
63673
- var currentError = errorInfo;
63674
- tryElaborateArrayLikeErrors(source, target, reportErrors);
63675
- if (errorInfo !== currentError) {
63676
- maybeSuppress = !!errorInfo;
63677
- }
63678
- }
63679
- if (source.flags & 524288 /* Object */ && target.flags & 131068 /* Primitive */) {
63680
- tryElaborateErrorsForPrimitivesAndObjects(source, target);
63681
- }
63682
- else if (source.symbol && source.flags & 524288 /* Object */ && globalObjectType === source) {
63683
- reportError(ts.Diagnostics.The_Object_type_is_assignable_to_very_few_other_types_Did_you_mean_to_use_the_any_type_instead);
63684
- }
63685
- else if (isComparingJsxAttributes && target.flags & 2097152 /* Intersection */) {
63686
- var targetTypes = target.types;
63687
- var intrinsicAttributes = getJsxType(JsxNames.IntrinsicAttributes, errorNode);
63688
- var intrinsicClassAttributes = getJsxType(JsxNames.IntrinsicClassAttributes, errorNode);
63689
- if (!isErrorType(intrinsicAttributes) && !isErrorType(intrinsicClassAttributes) &&
63690
- (ts.contains(targetTypes, intrinsicAttributes) || ts.contains(targetTypes, intrinsicClassAttributes))) {
63691
- // do not report top error
63692
- return result;
63693
- }
63694
- }
63695
- else {
63696
- errorInfo = elaborateNeverIntersection(errorInfo, originalTarget);
63697
- }
63698
- if (!headMessage && maybeSuppress) {
63699
- lastSkippedInfo = [source, target];
63700
- // Used by, eg, missing property checking to replace the top-level message with a more informative one
63701
- return result;
63702
- }
63703
- reportRelationError(headMessage, source, target);
63704
- }
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;
63705
63764
  }
63765
+ reportRelationError(headMessage, source, target);
63706
63766
  }
63707
63767
  function traceUnionsOrIntersectionsTooLarge(source, target) {
63708
63768
  if (!ts.tracing) {
@@ -63729,21 +63789,6 @@ var ts;
63729
63789
  }
63730
63790
  }
63731
63791
  }
63732
- function isIdenticalTo(source, target, recursionFlags) {
63733
- if (source.flags !== target.flags)
63734
- return 0 /* False */;
63735
- if (source.flags & 67358815 /* Singleton */)
63736
- return -1 /* True */;
63737
- traceUnionsOrIntersectionsTooLarge(source, target);
63738
- if (source.flags & 3145728 /* UnionOrIntersection */) {
63739
- var result_7 = eachTypeRelatedToSomeType(source, target);
63740
- if (result_7) {
63741
- result_7 &= eachTypeRelatedToSomeType(target, source);
63742
- }
63743
- return result_7;
63744
- }
63745
- return recursiveTypeRelatedTo(source, target, /*reportErrors*/ false, 0 /* None */, recursionFlags);
63746
- }
63747
63792
  function getTypeOfPropertyInTypes(types, name) {
63748
63793
  var appendPropType = function (propTypes, type) {
63749
63794
  var _a;
@@ -63842,6 +63887,41 @@ var ts;
63842
63887
  function shouldCheckAsExcessProperty(prop, container) {
63843
63888
  return prop.valueDeclaration && container.valueDeclaration && prop.valueDeclaration.parent === container.valueDeclaration;
63844
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
+ }
63845
63925
  function eachTypeRelatedToSomeType(source, target) {
63846
63926
  var result = -1 /* True */;
63847
63927
  var sourceTypes = source.types;
@@ -63877,8 +63957,11 @@ var ts;
63877
63957
  }
63878
63958
  }
63879
63959
  if (reportErrors) {
63960
+ // Elaborate only if we can find a best matching type in the target union
63880
63961
  var bestMatchingType = getBestMatchingType(source, target, isRelatedTo);
63881
- isRelatedTo(source, bestMatchingType || targetTypes[targetTypes.length - 1], 2 /* Target */, /*reportErrors*/ true);
63962
+ if (bestMatchingType) {
63963
+ isRelatedTo(source, bestMatchingType, 2 /* Target */, /*reportErrors*/ true);
63964
+ }
63882
63965
  }
63883
63966
  return 0 /* False */;
63884
63967
  }
@@ -64014,7 +64097,7 @@ var ts;
64014
64097
  if (overflow) {
64015
64098
  return 0 /* False */;
64016
64099
  }
64017
- var keyIntersectionState = intersectionState | (inPropertyCheck ? 16 /* InPropertyCheck */ : 0);
64100
+ var keyIntersectionState = intersectionState | (inPropertyCheck ? 8 /* InPropertyCheck */ : 0);
64018
64101
  var id = getRelationKey(source, target, keyIntersectionState, relation, /*ingnoreConstraints*/ false);
64019
64102
  var entry = relation.get(id);
64020
64103
  if (entry !== undefined) {
@@ -64082,6 +64165,7 @@ var ts;
64082
64165
  return originalHandler(onlyUnreliable);
64083
64166
  };
64084
64167
  }
64168
+ var result;
64085
64169
  if (expandingFlags === 3 /* Both */) {
64086
64170
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.instant("checkTypes" /* CheckTypes */, "recursiveTypeRelatedTo_DepthLimit", {
64087
64171
  sourceId: source.id,
@@ -64091,8 +64175,13 @@ var ts;
64091
64175
  depth: sourceDepth,
64092
64176
  targetDepth: targetDepth
64093
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();
64094
64184
  }
64095
- var result = expandingFlags !== 3 /* Both */ ? structuredTypeRelatedTo(source, target, reportErrors, intersectionState) : 3 /* Maybe */;
64096
64185
  if (outofbandVarianceMarkerHandler) {
64097
64186
  outofbandVarianceMarkerHandler = originalHandler;
64098
64187
  }
@@ -64124,98 +64213,97 @@ var ts;
64124
64213
  return result;
64125
64214
  }
64126
64215
  function structuredTypeRelatedTo(source, target, reportErrors, intersectionState) {
64127
- ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("checkTypes" /* CheckTypes */, "structuredTypeRelatedTo", { sourceId: source.id, targetId: target.id });
64128
- var result = structuredTypeRelatedToWorker(source, target, reportErrors, intersectionState);
64129
- ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
64130
- return result;
64131
- }
64132
- function structuredTypeRelatedToWorker(source, target, reportErrors, intersectionState) {
64133
64216
  if (intersectionState & 4 /* PropertyCheck */) {
64134
64217
  return propertiesRelatedTo(source, target, reportErrors, /*excludedProperties*/ undefined, 0 /* None */);
64135
64218
  }
64136
- if (intersectionState & 8 /* UnionIntersectionCheck */) {
64137
- // Note that these checks are specifically ordered to produce correct results. In particular,
64138
- // we need to deconstruct unions before intersections (because unions are always at the top),
64139
- // and we need to handle "each" relations before "some" relations for the same kind of type.
64140
- if (source.flags & 1048576 /* Union */) {
64141
- return relation === comparableRelation ?
64142
- someTypeRelatedToType(source, target, reportErrors && !(source.flags & 131068 /* Primitive */), intersectionState & ~8 /* UnionIntersectionCheck */) :
64143
- eachTypeRelatedToType(source, target, reportErrors && !(source.flags & 131068 /* Primitive */), intersectionState & ~8 /* UnionIntersectionCheck */);
64144
- }
64145
- if (target.flags & 1048576 /* Union */) {
64146
- return typeRelatedToSomeType(getRegularTypeOfObjectLiteral(source), target, reportErrors && !(source.flags & 131068 /* Primitive */) && !(target.flags & 131068 /* Primitive */));
64147
- }
64148
- if (target.flags & 2097152 /* Intersection */) {
64149
- return typeRelatedToEachType(getRegularTypeOfObjectLiteral(source), target, reportErrors, 2 /* Target */);
64150
- }
64151
- // Source is an intersection. For the comparable relation, if the target is a primitive type we hoist the
64152
- // constraints of all non-primitive types in the source into a new intersection. We do this because the
64153
- // intersection may further constrain the constraints of the non-primitive types. For example, given a type
64154
- // parameter 'T extends 1 | 2', the intersection 'T & 1' should be reduced to '1' such that it doesn't
64155
- // appear to be comparable to '2'.
64156
- if (relation === comparableRelation && target.flags & 131068 /* Primitive */) {
64157
- var constraints = ts.sameMap(source.types, getBaseConstraintOrType);
64158
- if (constraints !== source.types) {
64159
- source = getIntersectionType(constraints);
64160
- if (!(source.flags & 2097152 /* Intersection */)) {
64161
- return isRelatedTo(source, target, 1 /* Source */, /*reportErrors*/ false);
64162
- }
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);
64163
64231
  }
64232
+ return result_8;
64164
64233
  }
64165
- // Check to see if any constituents of the intersection are immediately related to the target.
64166
- //
64167
- // Don't report errors though. Checking whether a constituent is related to the source is not actually
64168
- // useful and leads to some confusing error messages. Instead it is better to let the below checks
64169
- // take care of this, or to not elaborate at all. For instance,
64170
- //
64171
- // - For an object type (such as 'C = A & B'), users are usually more interested in structural errors.
64172
- //
64173
- // - For a union type (such as '(A | B) = (C & D)'), it's better to hold onto the whole intersection
64174
- // than to report that 'D' is not assignable to 'A' or 'B'.
64175
- //
64176
- // - For a primitive type or type parameter (such as 'number = A & B') there is no point in
64177
- // breaking the intersection apart.
64178
- return someTypeRelatedToType(source, target, /*reportErrors*/ false, 1 /* Source */);
64179
- }
64180
- var flags = source.flags & target.flags;
64181
- if (relation === identityRelation && !(flags & 524288 /* Object */)) {
64182
- if (flags & 4194304 /* Index */) {
64234
+ if (sourceFlags & 4194304 /* Index */) {
64183
64235
  return isRelatedTo(source.type, target.type, 3 /* Both */, /*reportErrors*/ false);
64184
64236
  }
64185
- var result_8 = 0 /* False */;
64186
- if (flags & 8388608 /* IndexedAccess */) {
64187
- if (result_8 = isRelatedTo(source.objectType, target.objectType, 3 /* Both */, /*reportErrors*/ false)) {
64188
- if (result_8 &= isRelatedTo(source.indexType, target.indexType, 3 /* Both */, /*reportErrors*/ false)) {
64189
- 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;
64190
64241
  }
64191
64242
  }
64192
64243
  }
64193
- if (flags & 16777216 /* Conditional */) {
64244
+ if (sourceFlags & 16777216 /* Conditional */) {
64194
64245
  if (source.root.isDistributive === target.root.isDistributive) {
64195
- if (result_8 = isRelatedTo(source.checkType, target.checkType, 3 /* Both */, /*reportErrors*/ false)) {
64196
- if (result_8 &= isRelatedTo(source.extendsType, target.extendsType, 3 /* Both */, /*reportErrors*/ false)) {
64197
- if (result_8 &= isRelatedTo(getTrueTypeFromConditionalType(source), getTrueTypeFromConditionalType(target), 3 /* Both */, /*reportErrors*/ false)) {
64198
- if (result_8 &= isRelatedTo(getFalseTypeFromConditionalType(source), getFalseTypeFromConditionalType(target), 3 /* Both */, /*reportErrors*/ false)) {
64199
- 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;
64200
64251
  }
64201
64252
  }
64202
64253
  }
64203
64254
  }
64204
64255
  }
64205
64256
  }
64206
- if (flags & 33554432 /* Substitution */) {
64257
+ if (sourceFlags & 33554432 /* Substitution */) {
64207
64258
  return isRelatedTo(source.substitute, target.substitute, 3 /* Both */, /*reportErrors*/ false);
64208
64259
  }
64209
- 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
+ }
64210
64302
  }
64211
- var result;
64212
- var originalErrorInfo;
64213
- var varianceCheckFailed = false;
64214
- var saveErrorInfo = captureErrorCalculationState();
64215
64303
  // We limit alias variance probing to only object and conditional types since their alias behavior
64216
64304
  // is more predictable than other, interned types, which may or may not have an alias depending on
64217
64305
  // the order in which things were checked.
64218
- if (source.flags & (524288 /* Object */ | 16777216 /* Conditional */) && source.aliasSymbol &&
64306
+ if (sourceFlags & (524288 /* Object */ | 16777216 /* Conditional */) && source.aliasSymbol &&
64219
64307
  source.aliasTypeArguments && source.aliasSymbol === target.aliasSymbol &&
64220
64308
  !(source.aliasTypeArgumentsContainsMarker || target.aliasTypeArgumentsContainsMarker)) {
64221
64309
  var variances = getAliasVariances(source.aliasSymbol);
@@ -64233,7 +64321,7 @@ var ts;
64233
64321
  isSingleElementGenericTupleType(target) && (target.target.readonly || isMutableArrayOrTuple(getBaseConstraintOfType(source) || source)) && (result = isRelatedTo(source, getTypeArguments(target)[0], 2 /* Target */))) {
64234
64322
  return result;
64235
64323
  }
64236
- if (target.flags & 262144 /* TypeParameter */) {
64324
+ if (targetFlags & 262144 /* TypeParameter */) {
64237
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].
64238
64326
  if (ts.getObjectFlags(source) & 32 /* Mapped */ && !source.declaration.nameType && isRelatedTo(getIndexType(target), getConstraintTypeFromMappedType(source), 3 /* Both */)) {
64239
64327
  if (!(getMappedTypeModifiers(source) & 4 /* IncludeOptional */)) {
@@ -64245,10 +64333,10 @@ var ts;
64245
64333
  }
64246
64334
  }
64247
64335
  }
64248
- else if (target.flags & 4194304 /* Index */) {
64336
+ else if (targetFlags & 4194304 /* Index */) {
64249
64337
  var targetType_1 = target.type;
64250
64338
  // A keyof S is related to a keyof T if T is related to S.
64251
- if (source.flags & 4194304 /* Index */) {
64339
+ if (sourceFlags & 4194304 /* Index */) {
64252
64340
  if (result = isRelatedTo(targetType_1, source.type, 3 /* Both */, /*reportErrors*/ false)) {
64253
64341
  return result;
64254
64342
  }
@@ -64299,8 +64387,8 @@ var ts;
64299
64387
  }
64300
64388
  }
64301
64389
  }
64302
- else if (target.flags & 8388608 /* IndexedAccess */) {
64303
- if (source.flags & 8388608 /* IndexedAccess */) {
64390
+ else if (targetFlags & 8388608 /* IndexedAccess */) {
64391
+ if (sourceFlags & 8388608 /* IndexedAccess */) {
64304
64392
  // Relate components directly before falling back to constraint relationships
64305
64393
  // A type S[K] is related to a type T[J] if S is related to T and K is related to J.
64306
64394
  if (result = isRelatedTo(source.objectType, target.objectType, 3 /* Both */, reportErrors)) {
@@ -64406,7 +64494,7 @@ var ts;
64406
64494
  }
64407
64495
  }
64408
64496
  }
64409
- else if (target.flags & 16777216 /* Conditional */) {
64497
+ else if (targetFlags & 16777216 /* Conditional */) {
64410
64498
  // If we reach 10 levels of nesting for the same conditional type, assume it is an infinitely expanding recursive
64411
64499
  // conditional type and bail out with a Ternary.Maybe result.
64412
64500
  if (isDeeplyNestedType(target, targetStack, targetDepth, 10)) {
@@ -64431,8 +64519,8 @@ var ts;
64431
64519
  }
64432
64520
  }
64433
64521
  }
64434
- else if (target.flags & 134217728 /* TemplateLiteral */) {
64435
- if (source.flags & 134217728 /* TemplateLiteral */) {
64522
+ else if (targetFlags & 134217728 /* TemplateLiteral */) {
64523
+ if (sourceFlags & 134217728 /* TemplateLiteral */) {
64436
64524
  if (relation === comparableRelation) {
64437
64525
  return templateLiteralTypesDefinitelyUnrelated(source, target) ? 0 /* False */ : -1 /* True */;
64438
64526
  }
@@ -64444,11 +64532,11 @@ var ts;
64444
64532
  return -1 /* True */;
64445
64533
  }
64446
64534
  }
64447
- if (source.flags & 8650752 /* TypeVariable */) {
64448
- // IndexedAccess comparisons are handled above in the `target.flags & TypeFlage.IndexedAccess` branch
64449
- 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 */)) {
64450
64538
  var constraint = getConstraintOfType(source);
64451
- if (!constraint || (source.flags & 262144 /* TypeParameter */ && constraint.flags & 1 /* Any */)) {
64539
+ if (!constraint || (sourceFlags & 262144 /* TypeParameter */ && constraint.flags & 1 /* Any */)) {
64452
64540
  // A type variable with no constraint is not related to the non-primitive object type.
64453
64541
  if (result = isRelatedTo(emptyObjectType, extractTypesOfKind(target, ~67108864 /* NonPrimitive */), 3 /* Both */)) {
64454
64542
  resetErrorInfo(saveErrorInfo);
@@ -64461,7 +64549,7 @@ var ts;
64461
64549
  return result;
64462
64550
  }
64463
64551
  // slower, fuller, this-instantiated check (necessary when comparing raw `this` types from base classes), see `subclassWithPolymorphicThisIsAssignable.ts` test for example
64464
- 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)) {
64465
64553
  resetErrorInfo(saveErrorInfo);
64466
64554
  return result;
64467
64555
  }
@@ -64478,14 +64566,14 @@ var ts;
64478
64566
  }
64479
64567
  }
64480
64568
  }
64481
- else if (source.flags & 4194304 /* Index */) {
64569
+ else if (sourceFlags & 4194304 /* Index */) {
64482
64570
  if (result = isRelatedTo(keyofConstraintType, target, 1 /* Source */, reportErrors)) {
64483
64571
  resetErrorInfo(saveErrorInfo);
64484
64572
  return result;
64485
64573
  }
64486
64574
  }
64487
- else if (source.flags & 134217728 /* TemplateLiteral */ && !(target.flags & 524288 /* Object */)) {
64488
- if (!(target.flags & 134217728 /* TemplateLiteral */)) {
64575
+ else if (sourceFlags & 134217728 /* TemplateLiteral */ && !(targetFlags & 524288 /* Object */)) {
64576
+ if (!(targetFlags & 134217728 /* TemplateLiteral */)) {
64489
64577
  var constraint = getBaseConstraintOfType(source);
64490
64578
  if (constraint && constraint !== source && (result = isRelatedTo(constraint, target, 1 /* Source */, reportErrors))) {
64491
64579
  resetErrorInfo(saveErrorInfo);
@@ -64493,8 +64581,8 @@ var ts;
64493
64581
  }
64494
64582
  }
64495
64583
  }
64496
- else if (source.flags & 268435456 /* StringMapping */) {
64497
- if (target.flags & 268435456 /* StringMapping */ && source.symbol === target.symbol) {
64584
+ else if (sourceFlags & 268435456 /* StringMapping */) {
64585
+ if (targetFlags & 268435456 /* StringMapping */ && source.symbol === target.symbol) {
64498
64586
  if (result = isRelatedTo(source.type, target.type, 3 /* Both */, reportErrors)) {
64499
64587
  resetErrorInfo(saveErrorInfo);
64500
64588
  return result;
@@ -64508,14 +64596,14 @@ var ts;
64508
64596
  }
64509
64597
  }
64510
64598
  }
64511
- else if (source.flags & 16777216 /* Conditional */) {
64599
+ else if (sourceFlags & 16777216 /* Conditional */) {
64512
64600
  // If we reach 10 levels of nesting for the same conditional type, assume it is an infinitely expanding recursive
64513
64601
  // conditional type and bail out with a Ternary.Maybe result.
64514
64602
  if (isDeeplyNestedType(source, sourceStack, sourceDepth, 10)) {
64515
64603
  resetErrorInfo(saveErrorInfo);
64516
64604
  return 3 /* Maybe */;
64517
64605
  }
64518
- if (target.flags & 16777216 /* Conditional */) {
64606
+ if (targetFlags & 16777216 /* Conditional */) {
64519
64607
  // Two conditional types 'T1 extends U1 ? X1 : Y1' and 'T2 extends U2 ? X2 : Y2' are related if
64520
64608
  // one of T1 and T2 is related to the other, U1 and U2 are identical types, X1 is related to X2,
64521
64609
  // and Y1 is related to Y2.
@@ -64575,15 +64663,21 @@ var ts;
64575
64663
  }
64576
64664
  return 0 /* False */;
64577
64665
  }
64578
- var sourceIsPrimitive = !!(source.flags & 131068 /* Primitive */);
64666
+ var sourceIsPrimitive = !!(sourceFlags & 131068 /* Primitive */);
64579
64667
  if (relation !== identityRelation) {
64580
64668
  source = getApparentType(source);
64669
+ sourceFlags = source.flags;
64581
64670
  }
64582
64671
  else if (isGenericMappedType(source)) {
64583
64672
  return 0 /* False */;
64584
64673
  }
64585
64674
  if (ts.getObjectFlags(source) & 4 /* Reference */ && ts.getObjectFlags(target) & 4 /* Reference */ && source.target === target.target &&
64586
64675
  !isTupleType(source) && !(ts.getObjectFlags(source) & 4096 /* MarkerType */ || ts.getObjectFlags(target) & 4096 /* MarkerType */)) {
64676
+ // When strictNullChecks is disabled, the element type of the empty array literal is undefinedWideningType,
64677
+ // and an empty array literal wouldn't be assignable to a `never[]` without this check.
64678
+ if (isEmptyArrayLiteralType(source)) {
64679
+ return -1 /* True */;
64680
+ }
64587
64681
  // We have type references to the same generic type, and the type references are not marker
64588
64682
  // type references (which are intended by be compared structurally). Obtain the variance
64589
64683
  // information for the type parameters and relate the type arguments accordingly.
@@ -64619,7 +64713,7 @@ var ts;
64619
64713
  // In a check of the form X = A & B, we will have previously checked if A relates to X or B relates
64620
64714
  // to X. Failing both of those we want to check if the aggregation of A and B's members structurally
64621
64715
  // relates to X. Thus, we include intersection types on the source side here.
64622
- if (source.flags & (524288 /* Object */ | 2097152 /* Intersection */) && target.flags & 524288 /* Object */) {
64716
+ if (sourceFlags & (524288 /* Object */ | 2097152 /* Intersection */) && targetFlags & 524288 /* Object */) {
64623
64717
  // Report structural errors only if we haven't reported any errors yet
64624
64718
  var reportStructuralErrors = reportErrors && errorInfo === saveErrorInfo.errorInfo && !sourceIsPrimitive;
64625
64719
  result = propertiesRelatedTo(source, target, reportStructuralErrors, /*excludedProperties*/ undefined, intersectionState);
@@ -64643,7 +64737,7 @@ var ts;
64643
64737
  // there exists a constituent of T for every combination of the discriminants of S
64644
64738
  // with respect to T. We do not report errors here, as we will use the existing
64645
64739
  // error result from checking each constituent of the union.
64646
- if (source.flags & (524288 /* Object */ | 2097152 /* Intersection */) && target.flags & 1048576 /* Union */) {
64740
+ if (sourceFlags & (524288 /* Object */ | 2097152 /* Intersection */) && targetFlags & 1048576 /* Union */) {
64647
64741
  var objectOnlyTarget = extractTypesOfKind(target, 524288 /* Object */ | 2097152 /* Intersection */ | 33554432 /* Substitution */);
64648
64742
  if (objectOnlyTarget.flags & 1048576 /* Union */) {
64649
64743
  var result_9 = typeRelatedToDiscriminatedType(source, objectOnlyTarget);
@@ -64890,6 +64984,15 @@ var ts;
64890
64984
  }
64891
64985
  return 0 /* False */;
64892
64986
  }
64987
+ // Ensure {readonly a: whatever} is not a subtype of {a: whatever},
64988
+ // while {a: whatever} is a subtype of {readonly a: whatever}.
64989
+ // This ensures the subtype relationship is ordered, and preventing declaration order
64990
+ // from deciding which type "wins" in union subtype reduction.
64991
+ // They're still assignable to one another, since `readonly` doesn't affect assignability.
64992
+ if ((relation === subtypeRelation || relation === strictSubtypeRelation) &&
64993
+ !!(sourcePropFlags & 64 /* Readonly */) && !(targetPropFlags & 64 /* Readonly */)) {
64994
+ return 0 /* False */;
64995
+ }
64893
64996
  // If the target comes from a partial union prop, allow `undefined` in the target type
64894
64997
  var related = isPropertySymbolTypeRelated(sourceProp, targetProp, getTypeOfSourceProperty, reportErrors, intersectionState);
64895
64998
  if (!related) {
@@ -65158,7 +65261,6 @@ var ts;
65158
65261
  }
65159
65262
  }
65160
65263
  var result = -1 /* True */;
65161
- var saveErrorInfo = captureErrorCalculationState();
65162
65264
  var incompatibleReporter = kind === 1 /* Construct */ ? reportIncompatibleConstructSignatureReturn : reportIncompatibleCallSignatureReturn;
65163
65265
  var sourceObjectFlags = ts.getObjectFlags(source);
65164
65266
  var targetObjectFlags = ts.getObjectFlags(target);
@@ -65199,6 +65301,7 @@ var ts;
65199
65301
  else {
65200
65302
  outer: for (var _i = 0, targetSignatures_1 = targetSignatures; _i < targetSignatures_1.length; _i++) {
65201
65303
  var t = targetSignatures_1[_i];
65304
+ var saveErrorInfo = captureErrorCalculationState();
65202
65305
  // Only elaborate errors from the first failure
65203
65306
  var shouldElaborateErrors = reportErrors;
65204
65307
  for (var _c = 0, sourceSignatures_1 = sourceSignatures; _c < sourceSignatures_1.length; _c++) {
@@ -65309,8 +65412,8 @@ var ts;
65309
65412
  var indexInfos = getIndexInfosOfType(target);
65310
65413
  var targetHasStringIndex = ts.some(indexInfos, function (info) { return info.keyType === stringType; });
65311
65414
  var result = -1 /* True */;
65312
- for (var _i = 0, indexInfos_3 = indexInfos; _i < indexInfos_3.length; _i++) {
65313
- var targetInfo = indexInfos_3[_i];
65415
+ for (var _i = 0, indexInfos_5 = indexInfos; _i < indexInfos_5.length; _i++) {
65416
+ var targetInfo = indexInfos_5[_i];
65314
65417
  var related = !sourceIsPrimitive && targetHasStringIndex && targetInfo.type.flags & 1 /* Any */ ? -1 /* True */ :
65315
65418
  isGenericMappedType(source) && targetHasStringIndex ? isRelatedTo(getTemplateTypeFromMappedType(source), targetInfo.type, 3 /* Both */, reportErrors) :
65316
65419
  typeRelatedToIndexInfo(source, targetInfo, reportErrors, intersectionState);
@@ -65917,10 +66020,10 @@ var ts;
65917
66020
  if (!(ts.getObjectFlags(type) & 4 /* Reference */) || !(ts.getObjectFlags(type.target) & 3 /* ClassOrInterface */)) {
65918
66021
  return undefined;
65919
66022
  }
65920
- if (ts.getObjectFlags(type) & 33554432 /* IdenticalBaseTypeCalculated */) {
65921
- return ts.getObjectFlags(type) & 67108864 /* IdenticalBaseTypeExists */ ? type.cachedEquivalentBaseType : undefined;
66023
+ if (ts.getObjectFlags(type) & 67108864 /* IdenticalBaseTypeCalculated */) {
66024
+ return ts.getObjectFlags(type) & 134217728 /* IdenticalBaseTypeExists */ ? type.cachedEquivalentBaseType : undefined;
65922
66025
  }
65923
- type.objectFlags |= 33554432 /* IdenticalBaseTypeCalculated */;
66026
+ type.objectFlags |= 67108864 /* IdenticalBaseTypeCalculated */;
65924
66027
  var target = type.target;
65925
66028
  if (ts.getObjectFlags(target) & 1 /* Class */) {
65926
66029
  var baseTypeNode = getBaseTypeNodeOfClass(target);
@@ -65941,7 +66044,7 @@ var ts;
65941
66044
  if (ts.length(getTypeArguments(type)) > ts.length(target.typeParameters)) {
65942
66045
  instantiatedBase = getTypeWithThisArgument(instantiatedBase, ts.last(getTypeArguments(type)));
65943
66046
  }
65944
- type.objectFlags |= 67108864 /* IdenticalBaseTypeExists */;
66047
+ type.objectFlags |= 134217728 /* IdenticalBaseTypeExists */;
65945
66048
  return type.cachedEquivalentBaseType = instantiatedBase;
65946
66049
  }
65947
66050
  function isEmptyLiteralType(type) {
@@ -66605,7 +66708,7 @@ var ts;
66605
66708
  var result = !!(type.flags & 465829888 /* Instantiable */ ||
66606
66709
  type.flags & 524288 /* Object */ && !isNonGenericTopLevelType(type) && (objectFlags & 4 /* Reference */ && (type.node || ts.forEach(getTypeArguments(type), couldContainTypeVariables)) ||
66607
66710
  objectFlags & 16 /* Anonymous */ && type.symbol && type.symbol.flags & (16 /* Function */ | 8192 /* Method */ | 32 /* Class */ | 2048 /* TypeLiteral */ | 4096 /* ObjectLiteral */) && type.symbol.declarations ||
66608
- objectFlags & (32 /* Mapped */ | 1024 /* ReverseMapped */ | 8388608 /* ObjectRestType */)) ||
66711
+ objectFlags & (32 /* Mapped */ | 1024 /* ReverseMapped */ | 8388608 /* ObjectRestType */ | 16777216 /* InstantiationExpressionType */)) ||
66609
66712
  type.flags & 3145728 /* UnionOrIntersection */ && !(type.flags & 1024 /* EnumLiteral */) && !isNonGenericTopLevelType(type) && ts.some(type.types, couldContainTypeVariables));
66610
66713
  if (type.flags & 3899393 /* ObjectFlagsType */) {
66611
66714
  type.objectFlags |= 1048576 /* CouldContainTypeVariablesComputed */ | (result ? 2097152 /* CouldContainTypeVariables */ : 0);
@@ -67522,8 +67625,8 @@ var ts;
67522
67625
  var priority = (ts.getObjectFlags(source) & ts.getObjectFlags(target) & 32 /* Mapped */) ? 8 /* HomomorphicMappedType */ : 0;
67523
67626
  var indexInfos = getIndexInfosOfType(target);
67524
67627
  if (isObjectTypeWithInferableIndex(source)) {
67525
- for (var _i = 0, indexInfos_4 = indexInfos; _i < indexInfos_4.length; _i++) {
67526
- var targetInfo = indexInfos_4[_i];
67628
+ for (var _i = 0, indexInfos_6 = indexInfos; _i < indexInfos_6.length; _i++) {
67629
+ var targetInfo = indexInfos_6[_i];
67527
67630
  var propTypes = [];
67528
67631
  for (var _a = 0, _b = getPropertiesOfType(source); _a < _b.length; _a++) {
67529
67632
  var prop = _b[_a];
@@ -67543,8 +67646,8 @@ var ts;
67543
67646
  }
67544
67647
  }
67545
67648
  }
67546
- for (var _e = 0, indexInfos_5 = indexInfos; _e < indexInfos_5.length; _e++) {
67547
- var targetInfo = indexInfos_5[_e];
67649
+ for (var _e = 0, indexInfos_7 = indexInfos; _e < indexInfos_7.length; _e++) {
67650
+ var targetInfo = indexInfos_7[_e];
67548
67651
  var sourceInfo = getApplicableIndexInfo(source, targetInfo.keyType);
67549
67652
  if (sourceInfo) {
67550
67653
  inferWithPriority(sourceInfo.type, targetInfo.type, priority);
@@ -68369,9 +68472,6 @@ var ts;
68369
68472
  getUnionType(ts.map(type.types, mapper), 1 /* Literal */, aliasSymbol, aliasTypeArguments) :
68370
68473
  mapType(type, mapper);
68371
68474
  }
68372
- function getConstituentCount(type) {
68373
- return type.flags & 1048576 /* Union */ ? type.types.length : 1;
68374
- }
68375
68475
  function extractTypesOfKind(type, kind) {
68376
68476
  return filterType(type, function (t) { return (t.flags & kind) !== 0; });
68377
68477
  }
@@ -73092,6 +73192,9 @@ var ts;
73092
73192
  if (compilerOptions.noPropertyAccessFromIndexSignature && ts.isPropertyAccessExpression(node)) {
73093
73193
  error(right, ts.Diagnostics.Property_0_comes_from_an_index_signature_so_it_must_be_accessed_with_0, ts.unescapeLeadingUnderscores(right.escapedText));
73094
73194
  }
73195
+ if (indexInfo.declaration && ts.getCombinedNodeFlags(indexInfo.declaration) & 134217728 /* Deprecated */) {
73196
+ addDeprecatedSuggestion(right, [indexInfo.declaration], right.escapedText);
73197
+ }
73095
73198
  }
73096
73199
  else {
73097
73200
  if (isDeprecatedSymbol(prop) && isUncalledFunctionReference(node, prop) && prop.declarations) {
@@ -75708,6 +75811,72 @@ var ts;
75708
75811
  return node.flags & 32 /* OptionalChain */ ? checkNonNullChain(node) :
75709
75812
  getNonNullableType(checkExpression(node.expression));
75710
75813
  }
75814
+ function checkExpressionWithTypeArguments(node) {
75815
+ checkGrammarExpressionWithTypeArguments(node);
75816
+ var exprType = node.kind === 227 /* ExpressionWithTypeArguments */ ? checkExpression(node.expression) :
75817
+ ts.isThisIdentifier(node.exprName) ? checkThisExpression(node.exprName) :
75818
+ checkExpression(node.exprName);
75819
+ var typeArguments = node.typeArguments;
75820
+ if (exprType === silentNeverType || isErrorType(exprType) || !ts.some(typeArguments)) {
75821
+ return exprType;
75822
+ }
75823
+ var hasSomeApplicableSignature = false;
75824
+ var nonApplicableType;
75825
+ var result = getInstantiatedType(exprType);
75826
+ var errorType = hasSomeApplicableSignature ? nonApplicableType : exprType;
75827
+ if (errorType) {
75828
+ diagnostics.add(ts.createDiagnosticForNodeArray(ts.getSourceFileOfNode(node), typeArguments, ts.Diagnostics.Type_0_has_no_signatures_for_which_the_type_argument_list_is_applicable, typeToString(errorType)));
75829
+ }
75830
+ return result;
75831
+ function getInstantiatedType(type) {
75832
+ var hasSignatures = false;
75833
+ var hasApplicableSignature = false;
75834
+ var result = getInstantiatedTypePart(type);
75835
+ hasSomeApplicableSignature || (hasSomeApplicableSignature = hasApplicableSignature);
75836
+ if (hasSignatures && !hasApplicableSignature) {
75837
+ nonApplicableType !== null && nonApplicableType !== void 0 ? nonApplicableType : (nonApplicableType = type);
75838
+ }
75839
+ return result;
75840
+ function getInstantiatedTypePart(type) {
75841
+ if (type.flags & 524288 /* Object */) {
75842
+ var resolved = resolveStructuredTypeMembers(type);
75843
+ var callSignatures = getInstantiatedSignatures(resolved.callSignatures);
75844
+ var constructSignatures = getInstantiatedSignatures(resolved.constructSignatures);
75845
+ hasSignatures || (hasSignatures = resolved.callSignatures.length !== 0 || resolved.constructSignatures.length !== 0);
75846
+ hasApplicableSignature || (hasApplicableSignature = callSignatures.length !== 0 || constructSignatures.length !== 0);
75847
+ if (callSignatures !== resolved.callSignatures || constructSignatures !== resolved.constructSignatures) {
75848
+ var result_11 = createAnonymousType(undefined, resolved.members, callSignatures, constructSignatures, resolved.indexInfos);
75849
+ result_11.objectFlags |= 16777216 /* InstantiationExpressionType */;
75850
+ result_11.node = node;
75851
+ return result_11;
75852
+ }
75853
+ }
75854
+ else if (type.flags & 58982400 /* InstantiableNonPrimitive */) {
75855
+ var constraint = getBaseConstraintOfType(type);
75856
+ if (constraint) {
75857
+ var instantiated = getInstantiatedTypePart(constraint);
75858
+ if (instantiated !== constraint) {
75859
+ return instantiated;
75860
+ }
75861
+ }
75862
+ }
75863
+ else if (type.flags & 1048576 /* Union */) {
75864
+ return mapType(type, getInstantiatedType);
75865
+ }
75866
+ else if (type.flags & 2097152 /* Intersection */) {
75867
+ return getIntersectionType(ts.sameMap(type.types, getInstantiatedTypePart));
75868
+ }
75869
+ return type;
75870
+ }
75871
+ }
75872
+ function getInstantiatedSignatures(signatures) {
75873
+ var applicableSignatures = ts.filter(signatures, function (sig) { return !!sig.typeParameters && hasCorrectTypeArgumentArity(sig, typeArguments); });
75874
+ return ts.sameMap(applicableSignatures, function (sig) {
75875
+ var typeArgumentTypes = checkTypeArguments(sig, typeArguments, /*reportErrors*/ true);
75876
+ return typeArgumentTypes ? getSignatureInstantiation(sig, typeArgumentTypes, ts.isInJSFile(sig.declaration)) : sig;
75877
+ });
75878
+ }
75879
+ }
75711
75880
  function checkMetaProperty(node) {
75712
75881
  checkGrammarMetaProperty(node);
75713
75882
  if (node.keywordToken === 103 /* NewKeyword */) {
@@ -76037,21 +76206,22 @@ var ts;
76037
76206
  if (links.type === unknownType) {
76038
76207
  links.type = getTypeFromBindingPattern(declaration.name);
76039
76208
  }
76040
- assignBindingElementTypes(declaration.name);
76209
+ assignBindingElementTypes(declaration.name, links.type);
76041
76210
  }
76042
76211
  }
76043
76212
  }
76044
76213
  // When contextual typing assigns a type to a parameter that contains a binding pattern, we also need to push
76045
76214
  // the destructured type into the contained binding elements.
76046
- function assignBindingElementTypes(pattern) {
76215
+ function assignBindingElementTypes(pattern, parentType) {
76047
76216
  for (var _i = 0, _a = pattern.elements; _i < _a.length; _i++) {
76048
76217
  var element = _a[_i];
76049
76218
  if (!ts.isOmittedExpression(element)) {
76219
+ var type = getBindingElementTypeFromParentType(element, parentType);
76050
76220
  if (element.name.kind === 79 /* Identifier */) {
76051
- getSymbolLinks(getSymbolOfNode(element)).type = getTypeForBindingElement(element);
76221
+ getSymbolLinks(getSymbolOfNode(element)).type = type;
76052
76222
  }
76053
76223
  else {
76054
- assignBindingElementTypes(element.name);
76224
+ assignBindingElementTypes(element.name, type);
76055
76225
  }
76056
76226
  }
76057
76227
  }
@@ -78223,6 +78393,8 @@ var ts;
78223
78393
  return checkAssertion(node);
78224
78394
  case 229 /* NonNullExpression */:
78225
78395
  return checkNonNullAssertion(node);
78396
+ case 227 /* ExpressionWithTypeArguments */:
78397
+ return checkExpressionWithTypeArguments(node);
78226
78398
  case 230 /* MetaProperty */:
78227
78399
  return checkMetaProperty(node);
78228
78400
  case 214 /* DeleteExpression */:
@@ -79426,12 +79598,12 @@ var ts;
79426
79598
  case 264 /* ImportEqualsDeclaration */:
79427
79599
  case 267 /* NamespaceImport */:
79428
79600
  case 266 /* ImportClause */:
79429
- var result_11 = 0 /* None */;
79601
+ var result_12 = 0 /* None */;
79430
79602
  var target = resolveAlias(getSymbolOfNode(d));
79431
79603
  ts.forEach(target.declarations, function (d) {
79432
- result_11 |= getDeclarationSpaces(d);
79604
+ result_12 |= getDeclarationSpaces(d);
79433
79605
  });
79434
- return result_11;
79606
+ return result_12;
79435
79607
  case 253 /* VariableDeclaration */:
79436
79608
  case 202 /* BindingElement */:
79437
79609
  case 255 /* FunctionDeclaration */:
@@ -79792,28 +79964,24 @@ var ts;
79792
79964
  if (returnType.flags & 1 /* Any */) {
79793
79965
  return;
79794
79966
  }
79967
+ var headMessage;
79795
79968
  var expectedReturnType;
79796
- var headMessage = getDiagnosticHeadMessageForDecoratorResolution(node);
79797
- var errorInfo;
79798
79969
  switch (node.parent.kind) {
79799
79970
  case 256 /* ClassDeclaration */:
79971
+ headMessage = ts.Diagnostics.Decorator_function_return_type_0_is_not_assignable_to_type_1;
79800
79972
  var classSymbol = getSymbolOfNode(node.parent);
79801
79973
  var classConstructorType = getTypeOfSymbol(classSymbol);
79802
79974
  expectedReturnType = getUnionType([classConstructorType, voidType]);
79803
79975
  break;
79804
- case 163 /* Parameter */:
79805
- expectedReturnType = voidType;
79806
- errorInfo = ts.chainDiagnosticMessages(
79807
- /*details*/ undefined, ts.Diagnostics.The_return_type_of_a_parameter_decorator_function_must_be_either_void_or_any);
79808
- break;
79809
79976
  case 166 /* PropertyDeclaration */:
79977
+ case 163 /* Parameter */:
79978
+ headMessage = ts.Diagnostics.Decorator_function_return_type_is_0_but_is_expected_to_be_void_or_any;
79810
79979
  expectedReturnType = voidType;
79811
- errorInfo = ts.chainDiagnosticMessages(
79812
- /*details*/ undefined, ts.Diagnostics.The_return_type_of_a_property_decorator_function_must_be_either_void_or_any);
79813
79980
  break;
79814
79981
  case 168 /* MethodDeclaration */:
79815
79982
  case 171 /* GetAccessor */:
79816
79983
  case 172 /* SetAccessor */:
79984
+ headMessage = ts.Diagnostics.Decorator_function_return_type_0_is_not_assignable_to_type_1;
79817
79985
  var methodType = getTypeOfNode(node.parent);
79818
79986
  var descriptorType = createTypedPropertyDescriptorType(methodType);
79819
79987
  expectedReturnType = getUnionType([descriptorType, voidType]);
@@ -79821,7 +79989,7 @@ var ts;
79821
79989
  default:
79822
79990
  return ts.Debug.fail();
79823
79991
  }
79824
- checkTypeAssignableTo(returnType, expectedReturnType, node, headMessage, function () { return errorInfo; });
79992
+ checkTypeAssignableTo(returnType, expectedReturnType, node, headMessage);
79825
79993
  }
79826
79994
  /**
79827
79995
  * If a TypeNode can be resolved to a value symbol imported from an external module, it is
@@ -81994,8 +82162,8 @@ var ts;
81994
82162
  }
81995
82163
  }
81996
82164
  if (indexInfos.length > 1) {
81997
- for (var _d = 0, indexInfos_6 = indexInfos; _d < indexInfos_6.length; _d++) {
81998
- var info = indexInfos_6[_d];
82165
+ for (var _d = 0, indexInfos_8 = indexInfos; _d < indexInfos_8.length; _d++) {
82166
+ var info = indexInfos_8[_d];
81999
82167
  checkIndexConstraintForIndexSignature(type, info);
82000
82168
  }
82001
82169
  }
@@ -82021,8 +82189,8 @@ var ts;
82021
82189
  error(errorNode, ts.Diagnostics.Property_0_of_type_1_is_not_assignable_to_2_index_type_3, symbolToString(prop), typeToString(propType), typeToString(info.keyType), typeToString(info.type));
82022
82190
  }
82023
82191
  };
82024
- for (var _i = 0, indexInfos_7 = indexInfos; _i < indexInfos_7.length; _i++) {
82025
- var info = indexInfos_7[_i];
82192
+ for (var _i = 0, indexInfos_9 = indexInfos; _i < indexInfos_9.length; _i++) {
82193
+ var info = indexInfos_9[_i];
82026
82194
  _loop_27(info);
82027
82195
  }
82028
82196
  }
@@ -82044,8 +82212,8 @@ var ts;
82044
82212
  error(errorNode, ts.Diagnostics._0_index_type_1_is_not_assignable_to_2_index_type_3, typeToString(checkInfo.keyType), typeToString(checkInfo.type), typeToString(info.keyType), typeToString(info.type));
82045
82213
  }
82046
82214
  };
82047
- for (var _i = 0, indexInfos_8 = indexInfos; _i < indexInfos_8.length; _i++) {
82048
- var info = indexInfos_8[_i];
82215
+ for (var _i = 0, indexInfos_10 = indexInfos; _i < indexInfos_10.length; _i++) {
82216
+ var info = indexInfos_10[_i];
82049
82217
  _loop_28(info);
82050
82218
  }
82051
82219
  }
@@ -85369,7 +85537,7 @@ var ts;
85369
85537
  if (resolvedTypeReferenceDirectives) {
85370
85538
  // populate reverse mapping: file path -> type reference directive that was resolved to this file
85371
85539
  fileToDirective = new ts.Map();
85372
- resolvedTypeReferenceDirectives.forEach(function (resolvedDirective, key) {
85540
+ resolvedTypeReferenceDirectives.forEach(function (resolvedDirective, key, mode) {
85373
85541
  if (!resolvedDirective || !resolvedDirective.resolvedFileName) {
85374
85542
  return;
85375
85543
  }
@@ -85377,7 +85545,7 @@ var ts;
85377
85545
  if (file) {
85378
85546
  // Add the transitive closure of path references loaded by this file (as long as they are not)
85379
85547
  // part of an existing type reference.
85380
- addReferencedFilesToTypeDirective(file, key);
85548
+ addReferencedFilesToTypeDirective(file, key, mode);
85381
85549
  }
85382
85550
  });
85383
85551
  }
@@ -85571,16 +85739,16 @@ var ts;
85571
85739
  }
85572
85740
  return false;
85573
85741
  }
85574
- function addReferencedFilesToTypeDirective(file, key) {
85742
+ function addReferencedFilesToTypeDirective(file, key, mode) {
85575
85743
  if (fileToDirective.has(file.path))
85576
85744
  return;
85577
- fileToDirective.set(file.path, key);
85745
+ fileToDirective.set(file.path, [key, mode]);
85578
85746
  for (var _i = 0, _a = file.referencedFiles; _i < _a.length; _i++) {
85579
- var fileName = _a[_i].fileName;
85747
+ var _b = _a[_i], fileName = _b.fileName, resolutionMode = _b.resolutionMode;
85580
85748
  var resolvedFile = ts.resolveTripleslashReference(fileName, file.fileName);
85581
85749
  var referencedFile = host.getSourceFile(resolvedFile);
85582
85750
  if (referencedFile) {
85583
- addReferencedFilesToTypeDirective(referencedFile, key);
85751
+ addReferencedFilesToTypeDirective(referencedFile, key, resolutionMode || file.impliedNodeFormat);
85584
85752
  }
85585
85753
  }
85586
85754
  }
@@ -87285,28 +87453,27 @@ var ts;
87285
87453
  }
87286
87454
  function findMostOverlappyType(source, unionTarget) {
87287
87455
  var bestMatch;
87288
- var matchingCount = 0;
87289
- for (var _i = 0, _a = unionTarget.types; _i < _a.length; _i++) {
87290
- var target = _a[_i];
87291
- var overlap = getIntersectionType([getIndexType(source), getIndexType(target)]);
87292
- if (overlap.flags & 4194304 /* Index */) {
87293
- // perfect overlap of keys
87294
- bestMatch = target;
87295
- matchingCount = Infinity;
87296
- }
87297
- else if (overlap.flags & 1048576 /* Union */) {
87298
- // We only want to account for literal types otherwise.
87299
- // If we have a union of index types, it seems likely that we
87300
- // needed to elaborate between two generic mapped types anyway.
87301
- var len = ts.length(ts.filter(overlap.types, isUnitType));
87302
- if (len >= matchingCount) {
87303
- bestMatch = target;
87304
- matchingCount = len;
87305
- }
87306
- }
87307
- else if (isUnitType(overlap) && 1 >= matchingCount) {
87308
- bestMatch = target;
87309
- matchingCount = 1;
87456
+ if (!(source.flags & (131068 /* Primitive */ | 406847488 /* InstantiablePrimitive */))) {
87457
+ var matchingCount = 0;
87458
+ for (var _i = 0, _a = unionTarget.types; _i < _a.length; _i++) {
87459
+ var target = _a[_i];
87460
+ if (!(target.flags & (131068 /* Primitive */ | 406847488 /* InstantiablePrimitive */))) {
87461
+ var overlap = getIntersectionType([getIndexType(source), getIndexType(target)]);
87462
+ if (overlap.flags & 4194304 /* Index */) {
87463
+ // perfect overlap of keys
87464
+ return target;
87465
+ }
87466
+ else if (isUnitType(overlap) || overlap.flags & 1048576 /* Union */) {
87467
+ // We only want to account for literal types otherwise.
87468
+ // If we have a union of index types, it seems likely that we
87469
+ // needed to elaborate between two generic mapped types anyway.
87470
+ var len = overlap.flags & 1048576 /* Union */ ? ts.countWhere(overlap.types, isUnitType) : 1;
87471
+ if (len >= matchingCount) {
87472
+ bestMatch = target;
87473
+ matchingCount = len;
87474
+ }
87475
+ }
87476
+ }
87310
87477
  }
87311
87478
  }
87312
87479
  return bestMatch;
@@ -87679,7 +87846,7 @@ var ts;
87679
87846
  return factory.updateConstructorTypeNode(node, nodesVisitor(node.modifiers, visitor, ts.isModifier), nodesVisitor(node.typeParameters, visitor, ts.isTypeParameterDeclaration), nodesVisitor(node.parameters, visitor, ts.isParameterDeclaration), nodeVisitor(node.type, visitor, ts.isTypeNode));
87680
87847
  case 180 /* TypeQuery */:
87681
87848
  ts.Debug.type(node);
87682
- return factory.updateTypeQueryNode(node, nodeVisitor(node.exprName, visitor, ts.isEntityName));
87849
+ return factory.updateTypeQueryNode(node, nodeVisitor(node.exprName, visitor, ts.isEntityName), nodesVisitor(node.typeArguments, visitor, ts.isTypeNode));
87683
87850
  case 181 /* TypeLiteral */:
87684
87851
  ts.Debug.type(node);
87685
87852
  return factory.updateTypeLiteralNode(node, nodesVisitor(node.members, visitor, ts.isTypeElement));
@@ -90571,8 +90738,8 @@ var ts;
90571
90738
  function generateClassElementDecorationExpressions(node, isStatic) {
90572
90739
  var members = getDecoratedClassElements(node, isStatic);
90573
90740
  var expressions;
90574
- for (var _i = 0, members_6 = members; _i < members_6.length; _i++) {
90575
- var member = members_6[_i];
90741
+ for (var _i = 0, members_8 = members; _i < members_8.length; _i++) {
90742
+ var member = members_8[_i];
90576
90743
  var expression = generateClassElementDecorationExpression(node, member);
90577
90744
  if (expression) {
90578
90745
  if (!expressions) {
@@ -95917,8 +96084,8 @@ var ts;
95917
96084
  function convertJsxChildrenToChildrenPropAssignment(children) {
95918
96085
  var nonWhitespaceChildren = ts.getSemanticJsxChildren(children);
95919
96086
  if (ts.length(nonWhitespaceChildren) === 1 && !nonWhitespaceChildren[0].dotDotDotToken) {
95920
- var result_12 = transformJsxChildToExpression(nonWhitespaceChildren[0]);
95921
- return result_12 && factory.createPropertyAssignment("children", result_12);
96087
+ var result_13 = transformJsxChildToExpression(nonWhitespaceChildren[0]);
96088
+ return result_13 && factory.createPropertyAssignment("children", result_13);
95922
96089
  }
95923
96090
  var result = ts.mapDefined(children, transformJsxChildToExpression);
95924
96091
  return ts.length(result) ? factory.createPropertyAssignment("children", factory.createArrayLiteralExpression(result)) : undefined;
@@ -106349,7 +106516,7 @@ var ts;
106349
106516
  var sourceFile = ts.createUnparsedSourceFile(prepend, "dts", stripInternal);
106350
106517
  hasNoDefaultLib_1 = hasNoDefaultLib_1 || !!sourceFile.hasNoDefaultLib;
106351
106518
  collectReferences(sourceFile, refs);
106352
- recordTypeReferenceDirectivesIfNecessary(sourceFile.typeReferenceDirectives);
106519
+ recordTypeReferenceDirectivesIfNecessary(ts.map(sourceFile.typeReferenceDirectives, function (ref) { return [ref.fileName, ref.resolutionMode]; }));
106353
106520
  collectLibs(sourceFile, libs);
106354
106521
  return sourceFile;
106355
106522
  }
@@ -106404,9 +106571,10 @@ var ts;
106404
106571
  return ts.map(ts.arrayFrom(libs.keys()), function (lib) { return ({ fileName: lib, pos: -1, end: -1 }); });
106405
106572
  }
106406
106573
  function getFileReferencesForUsedTypeReferences() {
106407
- return necessaryTypeReferences ? ts.mapDefined(ts.arrayFrom(necessaryTypeReferences.keys()), getFileReferenceForTypeName) : [];
106574
+ return necessaryTypeReferences ? ts.mapDefined(ts.arrayFrom(necessaryTypeReferences.keys()), getFileReferenceForSpecifierModeTuple) : [];
106408
106575
  }
106409
- function getFileReferenceForTypeName(typeName) {
106576
+ function getFileReferenceForSpecifierModeTuple(_a) {
106577
+ var typeName = _a[0], mode = _a[1];
106410
106578
  // Elide type references for which we have imports
106411
106579
  if (emittedImports) {
106412
106580
  for (var _i = 0, emittedImports_1 = emittedImports; _i < emittedImports_1.length; _i++) {
@@ -106422,7 +106590,7 @@ var ts;
106422
106590
  }
106423
106591
  }
106424
106592
  }
106425
- return { fileName: typeName, pos: -1, end: -1 };
106593
+ return __assign({ fileName: typeName, pos: -1, end: -1 }, (mode ? { resolutionMode: mode } : undefined));
106426
106594
  }
106427
106595
  function mapReferencesIntoArray(references, outputFilePath) {
106428
106596
  return function (file) {
@@ -106442,7 +106610,7 @@ var ts;
106442
106610
  // If some compiler option/symlink/whatever allows access to the file containing the ambient module declaration
106443
106611
  // via a non-relative name, emit a type reference directive to that non-relative name, rather than
106444
106612
  // a relative path to the declaration file
106445
- recordTypeReferenceDirectivesIfNecessary([specifier]);
106613
+ recordTypeReferenceDirectivesIfNecessary([[specifier, /*mode*/ undefined]]);
106446
106614
  return;
106447
106615
  }
106448
106616
  var fileName = ts.getRelativePathToDirectoryOrUrl(outputFilePath, declFileName, host.getCurrentDirectory(), host.getCanonicalFileName,
@@ -109555,6 +109723,8 @@ var ts;
109555
109723
  return emitAsExpression(node);
109556
109724
  case 229 /* NonNullExpression */:
109557
109725
  return emitNonNullExpression(node);
109726
+ case 227 /* ExpressionWithTypeArguments */:
109727
+ return emitExpressionWithTypeArguments(node);
109558
109728
  case 230 /* MetaProperty */:
109559
109729
  return emitMetaProperty(node);
109560
109730
  case 231 /* SyntheticExpression */:
@@ -109999,6 +110169,7 @@ var ts;
109999
110169
  writeKeyword("typeof");
110000
110170
  writeSpace();
110001
110171
  emit(node.exprName);
110172
+ emitTypeArguments(node, node.typeArguments);
110002
110173
  }
110003
110174
  function emitTypeLiteral(node) {
110004
110175
  writePunctuation("{");
@@ -111554,9 +111725,12 @@ var ts;
111554
111725
  for (var _d = 0, types_24 = types; _d < types_24.length; _d++) {
111555
111726
  var directive = types_24[_d];
111556
111727
  var pos = writer.getTextPos();
111557
- writeComment("/// <reference types=\"" + directive.fileName + "\" />");
111728
+ var resolutionMode = directive.resolutionMode && directive.resolutionMode !== (currentSourceFile === null || currentSourceFile === void 0 ? void 0 : currentSourceFile.impliedNodeFormat)
111729
+ ? "resolution-mode=\"" + (directive.resolutionMode === ts.ModuleKind.ESNext ? "import" : "require") + "\""
111730
+ : "";
111731
+ writeComment("/// <reference types=\"" + directive.fileName + "\" " + resolutionMode + "/>");
111558
111732
  if (bundleFileInfo)
111559
- bundleFileInfo.sections.push({ pos: pos, end: writer.getTextPos(), kind: "type" /* Type */, data: directive.fileName });
111733
+ 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 });
111560
111734
  writeLine();
111561
111735
  }
111562
111736
  for (var _e = 0, libs_1 = libs; _e < libs_1.length; _e++) {
@@ -114163,7 +114337,7 @@ var ts;
114163
114337
  }
114164
114338
  ts.flattenDiagnosticMessageText = flattenDiagnosticMessageText;
114165
114339
  /* @internal */
114166
- function loadWithLocalCache(names, containingFile, redirectedReference, loader) {
114340
+ function loadWithTypeDirectiveCache(names, containingFile, redirectedReference, containingFileMode, loader) {
114167
114341
  if (names.length === 0) {
114168
114342
  return [];
114169
114343
  }
@@ -114172,19 +114346,28 @@ var ts;
114172
114346
  for (var _i = 0, names_2 = names; _i < names_2.length; _i++) {
114173
114347
  var name = names_2[_i];
114174
114348
  var result = void 0;
114175
- if (cache.has(name)) {
114176
- result = cache.get(name);
114349
+ var mode = getModeForFileReference(name, containingFileMode);
114350
+ // We lower-case all type references because npm automatically lowercases all packages. See GH#9824.
114351
+ var strName = ts.isString(name) ? name : name.fileName.toLowerCase();
114352
+ var cacheKey = mode !== undefined ? mode + "|" + strName : strName;
114353
+ if (cache.has(cacheKey)) {
114354
+ result = cache.get(cacheKey);
114177
114355
  }
114178
114356
  else {
114179
- cache.set(name, result = loader(name, containingFile, redirectedReference));
114357
+ cache.set(cacheKey, result = loader(strName, containingFile, redirectedReference, mode));
114180
114358
  }
114181
114359
  resolutions.push(result);
114182
114360
  }
114183
114361
  return resolutions;
114184
114362
  }
114185
- ts.loadWithLocalCache = loadWithLocalCache;
114363
+ ts.loadWithTypeDirectiveCache = loadWithTypeDirectiveCache;
114186
114364
  ;
114187
114365
  /* @internal */
114366
+ function getModeForFileReference(ref, containingFileMode) {
114367
+ return (ts.isString(ref) ? containingFileMode : ref.resolutionMode) || containingFileMode;
114368
+ }
114369
+ ts.getModeForFileReference = getModeForFileReference;
114370
+ /* @internal */
114188
114371
  function getModeForResolutionAtIndex(file, index) {
114189
114372
  if (file.impliedNodeFormat === undefined)
114190
114373
  return undefined;
@@ -114287,7 +114470,7 @@ var ts;
114287
114470
  var _d, _e, _f, _g;
114288
114471
  var file = ts.Debug.checkDefined(getSourceFileByPath(ref.file));
114289
114472
  var kind = ref.kind, index = ref.index;
114290
- var pos, end, packageId;
114473
+ var pos, end, packageId, resolutionMode;
114291
114474
  switch (kind) {
114292
114475
  case ts.FileIncludeKind.Import:
114293
114476
  var importLiteral = getModuleNameStringLiteralAt(file, index);
@@ -114301,8 +114484,8 @@ var ts;
114301
114484
  (_a = file.referencedFiles[index], pos = _a.pos, end = _a.end);
114302
114485
  break;
114303
114486
  case ts.FileIncludeKind.TypeReferenceDirective:
114304
- (_b = file.typeReferenceDirectives[index], pos = _b.pos, end = _b.end);
114305
- 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;
114487
+ (_b = file.typeReferenceDirectives[index], pos = _b.pos, end = _b.end, resolutionMode = _b.resolutionMode);
114488
+ 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;
114306
114489
  break;
114307
114490
  case ts.FileIncludeKind.LibReferenceDirective:
114308
114491
  (_c = file.libReferenceDirectives[index], pos = _c.pos, end = _c.end);
@@ -114546,7 +114729,7 @@ var ts;
114546
114729
  var fileReasons = ts.createMultiMap();
114547
114730
  var cachedBindAndCheckDiagnosticsForFile = {};
114548
114731
  var cachedDeclarationDiagnosticsForFile = {};
114549
- var resolvedTypeReferenceDirectives = new ts.Map();
114732
+ var resolvedTypeReferenceDirectives = ts.createModeAwareCache();
114550
114733
  var fileProcessingDiagnostics;
114551
114734
  // The below settings are to track if a .js file should be add to the program if loaded via searching under node_modules.
114552
114735
  // This works as imported modules are discovered recursively in a depth first manner, specifically:
@@ -114599,12 +114782,12 @@ var ts;
114599
114782
  }
114600
114783
  var actualResolveTypeReferenceDirectiveNamesWorker;
114601
114784
  if (host.resolveTypeReferenceDirectives) {
114602
- actualResolveTypeReferenceDirectiveNamesWorker = function (typeDirectiveNames, containingFile, redirectedReference) { return host.resolveTypeReferenceDirectives(ts.Debug.checkEachDefined(typeDirectiveNames), containingFile, redirectedReference, options); };
114785
+ actualResolveTypeReferenceDirectiveNamesWorker = function (typeDirectiveNames, containingFile, redirectedReference, containingFileMode) { return host.resolveTypeReferenceDirectives(ts.Debug.checkEachDefined(typeDirectiveNames), containingFile, redirectedReference, options, containingFileMode); };
114603
114786
  }
114604
114787
  else {
114605
114788
  typeReferenceDirectiveResolutionCache = ts.createTypeReferenceDirectiveResolutionCache(currentDirectory, getCanonicalFileName, /*options*/ undefined, moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache());
114606
- var loader_2 = function (typesRef, containingFile, redirectedReference) { return ts.resolveTypeReferenceDirective(typesRef, containingFile, options, host, redirectedReference, typeReferenceDirectiveResolutionCache).resolvedTypeReferenceDirective; }; // TODO: GH#18217
114607
- actualResolveTypeReferenceDirectiveNamesWorker = function (typeReferenceDirectiveNames, containingFile, redirectedReference) { return loadWithLocalCache(ts.Debug.checkEachDefined(typeReferenceDirectiveNames), containingFile, redirectedReference, loader_2); };
114789
+ var loader_2 = function (typesRef, containingFile, redirectedReference, resolutionMode) { return ts.resolveTypeReferenceDirective(typesRef, containingFile, options, host, redirectedReference, typeReferenceDirectiveResolutionCache, resolutionMode).resolvedTypeReferenceDirective; }; // TODO: GH#18217
114790
+ actualResolveTypeReferenceDirectiveNamesWorker = function (typeReferenceDirectiveNames, containingFile, redirectedReference, containingFileMode) { return loadWithTypeDirectiveCache(ts.Debug.checkEachDefined(typeReferenceDirectiveNames), containingFile, redirectedReference, containingFileMode, loader_2); };
114608
114791
  }
114609
114792
  // Map from a stringified PackageId to the source file with that id.
114610
114793
  // Only one source file may have a given packageId. Others become redirects (see createRedirectSourceFile).
@@ -114701,7 +114884,8 @@ var ts;
114701
114884
  var containingFilename = ts.combinePaths(containingDirectory, ts.inferredTypesContainingFile);
114702
114885
  var resolutions = resolveTypeReferenceDirectiveNamesWorker(typeReferences, containingFilename);
114703
114886
  for (var i = 0; i < typeReferences.length; i++) {
114704
- processTypeReferenceDirective(typeReferences[i], resolutions[i], { kind: ts.FileIncludeKind.AutomaticTypeDirectiveFile, typeReference: typeReferences[i], packageId: (_c = resolutions[i]) === null || _c === void 0 ? void 0 : _c.packageId });
114887
+ // under node12/nodenext module resolution, load `types`/ata include names as cjs resolution results by passing an `undefined` mode
114888
+ 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 });
114705
114889
  }
114706
114890
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
114707
114891
  }
@@ -114861,9 +115045,10 @@ var ts;
114861
115045
  return [];
114862
115046
  var containingFileName = !ts.isString(containingFile) ? ts.getNormalizedAbsolutePath(containingFile.originalFileName, currentDirectory) : containingFile;
114863
115047
  var redirectedReference = !ts.isString(containingFile) ? getRedirectReferenceForResolution(containingFile) : undefined;
115048
+ var containingFileMode = !ts.isString(containingFile) ? containingFile.impliedNodeFormat : undefined;
114864
115049
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("program" /* Program */, "resolveTypeReferenceDirectiveNamesWorker", { containingFileName: containingFileName });
114865
115050
  ts.performance.mark("beforeResolveTypeReference");
114866
- var result = actualResolveTypeReferenceDirectiveNamesWorker(typeDirectiveNames, containingFileName, redirectedReference);
115051
+ var result = actualResolveTypeReferenceDirectiveNamesWorker(typeDirectiveNames, containingFileName, redirectedReference, containingFileMode);
114867
115052
  ts.performance.mark("afterResolveTypeReference");
114868
115053
  ts.performance.measure("ResolveTypeReference", "beforeResolveTypeReference", "afterResolveTypeReference");
114869
115054
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
@@ -114958,15 +115143,15 @@ var ts;
114958
115143
  // which per above occurred during the current program creation.
114959
115144
  // Since we assume the filesystem does not change during program creation,
114960
115145
  // it is safe to reuse resolutions from the earlier call.
114961
- var result_13 = [];
115146
+ var result_14 = [];
114962
115147
  var i = 0;
114963
115148
  for (var _i = 0, moduleNames_1 = moduleNames; _i < moduleNames_1.length; _i++) {
114964
115149
  var moduleName = moduleNames_1[_i];
114965
115150
  var resolvedModule = file.resolvedModules.get(moduleName, getModeForResolutionAtIndex(file, i));
114966
115151
  i++;
114967
- result_13.push(resolvedModule);
115152
+ result_14.push(resolvedModule);
114968
115153
  }
114969
- return result_13;
115154
+ return result_14;
114970
115155
  }
114971
115156
  // At this point, we know at least one of the following hold:
114972
115157
  // - file has local declarations for ambient modules
@@ -115255,8 +115440,7 @@ var ts;
115255
115440
  else {
115256
115441
  newSourceFile.resolvedModules = oldSourceFile.resolvedModules;
115257
115442
  }
115258
- // We lower-case all type references because npm automatically lowercases all packages. See GH#9824.
115259
- var typesReferenceDirectives = ts.map(newSourceFile.typeReferenceDirectives, function (ref) { return ts.toFileNameLowerCase(ref.fileName); });
115443
+ var typesReferenceDirectives = newSourceFile.typeReferenceDirectives;
115260
115444
  var typeReferenceResolutions = resolveTypeReferenceDirectiveNamesWorker(typesReferenceDirectives, newSourceFile);
115261
115445
  // ensure that types resolutions are still correct
115262
115446
  var typeReferenceResolutionsChanged = ts.hasChangesInResolutions(typesReferenceDirectives, typeReferenceResolutions, oldSourceFile.resolvedTypeReferenceDirectiveNames, oldSourceFile, ts.typeDirectiveIsEqualTo);
@@ -116335,8 +116519,7 @@ var ts;
116335
116519
  });
116336
116520
  }
116337
116521
  function processTypeReferenceDirectives(file) {
116338
- // We lower-case all type references because npm automatically lowercases all packages. See GH#9824.
116339
- var typeDirectives = ts.map(file.typeReferenceDirectives, function (ref) { return ts.toFileNameLowerCase(ref.fileName); });
116522
+ var typeDirectives = file.typeReferenceDirectives;
116340
116523
  if (!typeDirectives) {
116341
116524
  return;
116342
116525
  }
@@ -116347,17 +116530,21 @@ var ts;
116347
116530
  // store resolved type directive on the file
116348
116531
  var fileName = ts.toFileNameLowerCase(ref.fileName);
116349
116532
  ts.setResolvedTypeReferenceDirective(file, fileName, resolvedTypeReferenceDirective);
116350
- processTypeReferenceDirective(fileName, resolvedTypeReferenceDirective, { kind: ts.FileIncludeKind.TypeReferenceDirective, file: file.path, index: index, });
116533
+ var mode = ref.resolutionMode || file.impliedNodeFormat;
116534
+ if (mode && ts.getEmitModuleResolutionKind(options) !== ts.ModuleResolutionKind.Node12 && ts.getEmitModuleResolutionKind(options) !== ts.ModuleResolutionKind.NodeNext) {
116535
+ programDiagnostics.add(ts.createDiagnosticForRange(file, ref, ts.Diagnostics.Resolution_modes_are_only_supported_when_moduleResolution_is_node12_or_nodenext));
116536
+ }
116537
+ processTypeReferenceDirective(fileName, mode, resolvedTypeReferenceDirective, { kind: ts.FileIncludeKind.TypeReferenceDirective, file: file.path, index: index, });
116351
116538
  }
116352
116539
  }
116353
- function processTypeReferenceDirective(typeReferenceDirective, resolvedTypeReferenceDirective, reason) {
116540
+ function processTypeReferenceDirective(typeReferenceDirective, mode, resolvedTypeReferenceDirective, reason) {
116354
116541
  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 });
116355
- processTypeReferenceDirectiveWorker(typeReferenceDirective, resolvedTypeReferenceDirective, reason);
116542
+ processTypeReferenceDirectiveWorker(typeReferenceDirective, mode, resolvedTypeReferenceDirective, reason);
116356
116543
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
116357
116544
  }
116358
- function processTypeReferenceDirectiveWorker(typeReferenceDirective, resolvedTypeReferenceDirective, reason) {
116545
+ function processTypeReferenceDirectiveWorker(typeReferenceDirective, mode, resolvedTypeReferenceDirective, reason) {
116359
116546
  // If we already found this library as a primary reference - nothing to do
116360
- var previousResolution = resolvedTypeReferenceDirectives.get(typeReferenceDirective);
116547
+ var previousResolution = resolvedTypeReferenceDirectives.get(typeReferenceDirective, mode);
116361
116548
  if (previousResolution && previousResolution.primary) {
116362
116549
  return;
116363
116550
  }
@@ -116396,7 +116583,7 @@ var ts;
116396
116583
  addFilePreprocessingFileExplainingDiagnostic(/*file*/ undefined, reason, ts.Diagnostics.Cannot_find_type_definition_file_for_0, [typeReferenceDirective]);
116397
116584
  }
116398
116585
  if (saveResolution) {
116399
- resolvedTypeReferenceDirectives.set(typeReferenceDirective, resolvedTypeReferenceDirective);
116586
+ resolvedTypeReferenceDirectives.set(typeReferenceDirective, mode, resolvedTypeReferenceDirective);
116400
116587
  }
116401
116588
  }
116402
116589
  function pathForLibFile(libFileName) {
@@ -119214,9 +119401,9 @@ var ts;
119214
119401
  });
119215
119402
  hasChangedAutomaticTypeDirectiveNames = false;
119216
119403
  }
119217
- function resolveModuleName(moduleName, containingFile, compilerOptions, host, redirectedReference) {
119404
+ function resolveModuleName(moduleName, containingFile, compilerOptions, host, redirectedReference, _containingSourceFile, mode) {
119218
119405
  var _a;
119219
- var primaryResult = ts.resolveModuleName(moduleName, containingFile, compilerOptions, host, moduleResolutionCache, redirectedReference);
119406
+ var primaryResult = ts.resolveModuleName(moduleName, containingFile, compilerOptions, host, moduleResolutionCache, redirectedReference, mode);
119220
119407
  // return result immediately only if global cache support is not enabled or if it is .ts, .tsx or .d.ts
119221
119408
  if (!resolutionHost.getGlobalCache) {
119222
119409
  return primaryResult;
@@ -119237,12 +119424,12 @@ var ts;
119237
119424
  // Default return the result from the first pass
119238
119425
  return primaryResult;
119239
119426
  }
119240
- function resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference) {
119241
- return ts.resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference, typeReferenceDirectiveResolutionCache);
119427
+ function resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference, _containingSourceFile, resolutionMode) {
119428
+ return ts.resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference, typeReferenceDirectiveResolutionCache, resolutionMode);
119242
119429
  }
119243
119430
  function resolveNamesWithLocalCache(_a) {
119244
119431
  var _b, _c, _d;
119245
- 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;
119432
+ 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;
119246
119433
  var path = resolutionHost.toPath(containingFile);
119247
119434
  var resolutionsInFile = cache.get(path) || cache.set(path, ts.createModeAwareCache()).get(path);
119248
119435
  var dirPath = ts.getDirectoryPath(path);
@@ -119264,8 +119451,15 @@ var ts;
119264
119451
  var seenNamesInFile = ts.createModeAwareCache();
119265
119452
  var i = 0;
119266
119453
  for (var _i = 0, names_4 = names; _i < names_4.length; _i++) {
119267
- var name = names_4[_i];
119268
- var mode = containingSourceFile ? ts.getModeForResolutionAtIndex(containingSourceFile, i) : undefined;
119454
+ var entry = names_4[_i];
119455
+ var name = ts.isString(entry) ? entry : entry.fileName.toLowerCase();
119456
+ // Imports supply a `containingSourceFile` but no `containingSourceFileMode` - it would be redundant
119457
+ // they require calculating the mode for a given import from it's position in the resolution table, since a given
119458
+ // import's syntax may override the file's default mode.
119459
+ // Type references instead supply a `containingSourceFileMode` and a non-string entry which contains
119460
+ // a default file mode override if applicable.
119461
+ var mode = !ts.isString(entry) ? ts.getModeForFileReference(entry, containingSourceFileMode) :
119462
+ containingSourceFile ? ts.getModeForResolutionAtIndex(containingSourceFile, i) : undefined;
119269
119463
  i++;
119270
119464
  var resolution = resolutionsInFile.get(name, mode);
119271
119465
  // Resolution is valid if it is present and not invalidated
@@ -119294,7 +119488,7 @@ var ts;
119294
119488
  }
119295
119489
  }
119296
119490
  else {
119297
- resolution = loader(name, containingFile, compilerOptions, ((_c = resolutionHost.getCompilerHost) === null || _c === void 0 ? void 0 : _c.call(resolutionHost)) || resolutionHost, redirectedReference, containingSourceFile);
119491
+ resolution = loader(name, containingFile, compilerOptions, ((_c = resolutionHost.getCompilerHost) === null || _c === void 0 ? void 0 : _c.call(resolutionHost)) || resolutionHost, redirectedReference, containingSourceFile, mode);
119298
119492
  perDirectoryResolution.set(name, mode, resolution);
119299
119493
  if (resolutionHost.onDiscoveredSymlink && resolutionIsSymlink(resolution)) {
119300
119494
  resolutionHost.onDiscoveredSymlink();
@@ -119358,7 +119552,7 @@ var ts;
119358
119552
  return oldResult.resolvedFileName === newResult.resolvedFileName;
119359
119553
  }
119360
119554
  }
119361
- function resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference) {
119555
+ function resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference, containingFileMode) {
119362
119556
  return resolveNamesWithLocalCache({
119363
119557
  names: typeDirectiveNames,
119364
119558
  containingFile: containingFile,
@@ -119368,6 +119562,7 @@ var ts;
119368
119562
  loader: resolveTypeReferenceDirective,
119369
119563
  getResolutionWithResolvedFileName: getResolvedTypeReferenceDirective,
119370
119564
  shouldRetryResolution: function (resolution) { return resolution.resolvedTypeReferenceDirective === undefined; },
119565
+ containingSourceFileMode: containingFileMode
119371
119566
  });
119372
119567
  }
119373
119568
  function resolveModuleNames(moduleNames, containingFile, reusedNames, redirectedReference, containingSourceFile) {
@@ -120074,9 +120269,9 @@ var ts;
120074
120269
  if (!preferSymlinks) {
120075
120270
  // Symlinks inside ignored paths are already filtered out of the symlink cache,
120076
120271
  // so we only need to remove them from the realpath filenames.
120077
- var result_14 = ts.forEach(targets, function (p) { return !(shouldFilterIgnoredPaths && ts.containsIgnoredPath(p)) && cb(p, referenceRedirect === p); });
120078
- if (result_14)
120079
- return result_14;
120272
+ var result_15 = ts.forEach(targets, function (p) { return !(shouldFilterIgnoredPaths && ts.containsIgnoredPath(p)) && cb(p, referenceRedirect === p); });
120273
+ if (result_15)
120274
+ return result_15;
120080
120275
  }
120081
120276
  var symlinkedDirectories = (_a = host.getSymlinkCache) === null || _a === void 0 ? void 0 : _a.call(host).getSymlinkedDirectoriesByRealpath();
120082
120277
  var fullImportedFileName = ts.getNormalizedAbsolutePath(importedFileName, cwd);
@@ -120096,10 +120291,10 @@ var ts;
120096
120291
  for (var _i = 0, symlinkDirectories_1 = symlinkDirectories; _i < symlinkDirectories_1.length; _i++) {
120097
120292
  var symlinkDirectory = symlinkDirectories_1[_i];
120098
120293
  var option = ts.resolvePath(symlinkDirectory, relative);
120099
- var result_15 = cb(option, target === referenceRedirect);
120294
+ var result_16 = cb(option, target === referenceRedirect);
120100
120295
  shouldFilterIgnoredPaths = true; // We found a non-ignored path in symlinks, so we can reject ignored-path realpaths
120101
- if (result_15)
120102
- return result_15;
120296
+ if (result_16)
120297
+ return result_16;
120103
120298
  }
120104
120299
  });
120105
120300
  });
@@ -121276,7 +121471,7 @@ var ts;
121276
121471
  }
121277
121472
  return host.resolveTypeReferenceDirectives.apply(host, args);
121278
121473
  }) :
121279
- (function (typeDirectiveNames, containingFile, redirectedReference) { return resolutionCache.resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference); });
121474
+ (function (typeDirectiveNames, containingFile, redirectedReference, _options, containingFileMode) { return resolutionCache.resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference, containingFileMode); });
121280
121475
  var userProvidedResolution = !!host.resolveModuleNames || !!host.resolveTypeReferenceDirectives;
121281
121476
  builderProgram = readBuilderProgram(compilerOptions, compilerHost);
121282
121477
  synchronizeProgram();
@@ -122012,9 +122207,9 @@ var ts;
122012
122207
  compilerHost.getModuleResolutionCache = function () { return moduleResolutionCache; };
122013
122208
  }
122014
122209
  if (!compilerHost.resolveTypeReferenceDirectives) {
122015
- var loader_4 = function (moduleName, containingFile, redirectedReference) { return ts.resolveTypeReferenceDirective(moduleName, containingFile, state.projectCompilerOptions, compilerHost, redirectedReference, state.typeReferenceDirectiveResolutionCache).resolvedTypeReferenceDirective; };
122016
- compilerHost.resolveTypeReferenceDirectives = function (typeReferenceDirectiveNames, containingFile, redirectedReference) {
122017
- return ts.loadWithLocalCache(ts.Debug.checkEachDefined(typeReferenceDirectiveNames), containingFile, redirectedReference, loader_4);
122210
+ var loader_4 = function (moduleName, containingFile, redirectedReference, containingFileMode) { return ts.resolveTypeReferenceDirective(moduleName, containingFile, state.projectCompilerOptions, compilerHost, redirectedReference, state.typeReferenceDirectiveResolutionCache, containingFileMode).resolvedTypeReferenceDirective; };
122211
+ compilerHost.resolveTypeReferenceDirectives = function (typeReferenceDirectiveNames, containingFile, redirectedReference, _options, containingFileMode) {
122212
+ return ts.loadWithTypeDirectiveCache(ts.Debug.checkEachDefined(typeReferenceDirectiveNames), containingFile, redirectedReference, containingFileMode, loader_4);
122018
122213
  };
122019
122214
  }
122020
122215
  var _a = ts.createWatchFactory(hostWithWatch, options), watchFile = _a.watchFile, watchDirectory = _a.watchDirectory, writeLog = _a.writeLog;