typescript 4.6.0-dev.20220209 → 4.7.0-dev.20220215

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.20220209";
92
+ ts.version = ts.versionMajorMinor + ".0-dev.20220215";
93
93
  /* @internal */
94
94
  var Comparison;
95
95
  (function (Comparison) {
@@ -7625,18 +7625,6 @@ var ts;
7625
7625
  return getCanonicalFileName(nonCanonicalizedPath);
7626
7626
  }
7627
7627
  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
7628
  function removeTrailingDirectorySeparator(path) {
7641
7629
  if (hasTrailingDirectorySeparator(path)) {
7642
7630
  return path.substr(0, path.length - 1);
@@ -8034,10 +8022,10 @@ var ts;
8034
8022
  A_type_predicate_cannot_reference_a_rest_parameter: diag(1229, ts.DiagnosticCategory.Error, "A_type_predicate_cannot_reference_a_rest_parameter_1229", "A type predicate cannot reference a rest parameter."),
8035
8023
  A_type_predicate_cannot_reference_element_0_in_a_binding_pattern: diag(1230, ts.DiagnosticCategory.Error, "A_type_predicate_cannot_reference_element_0_in_a_binding_pattern_1230", "A type predicate cannot reference element '{0}' in a binding pattern."),
8036
8024
  An_export_assignment_must_be_at_the_top_level_of_a_file_or_module_declaration: diag(1231, ts.DiagnosticCategory.Error, "An_export_assignment_must_be_at_the_top_level_of_a_file_or_module_declaration_1231", "An export assignment must be at the top level of a file or module declaration."),
8037
- An_import_declaration_can_only_be_used_in_a_namespace_or_module: diag(1232, ts.DiagnosticCategory.Error, "An_import_declaration_can_only_be_used_in_a_namespace_or_module_1232", "An import declaration can only be used in a namespace or module."),
8038
- An_export_declaration_can_only_be_used_in_a_module: diag(1233, ts.DiagnosticCategory.Error, "An_export_declaration_can_only_be_used_in_a_module_1233", "An export declaration can only be used in a module."),
8025
+ An_import_declaration_can_only_be_used_at_the_top_level_of_a_namespace_or_module: diag(1232, ts.DiagnosticCategory.Error, "An_import_declaration_can_only_be_used_at_the_top_level_of_a_namespace_or_module_1232", "An import declaration can only be used at the top level of a namespace or module."),
8026
+ An_export_declaration_can_only_be_used_at_the_top_level_of_a_namespace_or_module: diag(1233, ts.DiagnosticCategory.Error, "An_export_declaration_can_only_be_used_at_the_top_level_of_a_namespace_or_module_1233", "An export declaration can only be used at the top level of a namespace or module."),
8039
8027
  An_ambient_module_declaration_is_only_allowed_at_the_top_level_in_a_file: diag(1234, ts.DiagnosticCategory.Error, "An_ambient_module_declaration_is_only_allowed_at_the_top_level_in_a_file_1234", "An ambient module declaration is only allowed at the top level in a file."),
8040
- A_namespace_declaration_is_only_allowed_in_a_namespace_or_module: diag(1235, ts.DiagnosticCategory.Error, "A_namespace_declaration_is_only_allowed_in_a_namespace_or_module_1235", "A namespace declaration is only allowed in a namespace or module."),
8028
+ A_namespace_declaration_is_only_allowed_at_the_top_level_of_a_namespace_or_module: diag(1235, ts.DiagnosticCategory.Error, "A_namespace_declaration_is_only_allowed_at_the_top_level_of_a_namespace_or_module_1235", "A namespace declaration is only allowed at the top level of a namespace or module."),
8041
8029
  The_return_type_of_a_property_decorator_function_must_be_either_void_or_any: diag(1236, ts.DiagnosticCategory.Error, "The_return_type_of_a_property_decorator_function_must_be_either_void_or_any_1236", "The return type of a property decorator function must be either 'void' or 'any'."),
8042
8030
  The_return_type_of_a_parameter_decorator_function_must_be_either_void_or_any: diag(1237, ts.DiagnosticCategory.Error, "The_return_type_of_a_parameter_decorator_function_must_be_either_void_or_any_1237", "The return type of a parameter decorator function must be either 'void' or 'any'."),
8043
8031
  Unable_to_resolve_signature_of_class_decorator_when_called_as_an_expression: diag(1238, ts.DiagnosticCategory.Error, "Unable_to_resolve_signature_of_class_decorator_when_called_as_an_expression_1238", "Unable to resolve signature of class decorator when called as an expression."),
@@ -8069,6 +8057,7 @@ var ts;
8069
8057
  An_optional_element_cannot_follow_a_rest_element: diag(1266, ts.DiagnosticCategory.Error, "An_optional_element_cannot_follow_a_rest_element_1266", "An optional element cannot follow a rest element."),
8070
8058
  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
8059
  An_index_signature_parameter_type_must_be_string_number_symbol_or_a_template_literal_type: diag(1268, ts.DiagnosticCategory.Error, "An_index_signature_parameter_type_must_be_string_number_symbol_or_a_template_literal_type_1268", "An index signature parameter type must be 'string', 'number', 'symbol', or a template literal type."),
8060
+ 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."),
8072
8061
  with_statements_are_not_allowed_in_an_async_function_block: diag(1300, ts.DiagnosticCategory.Error, "with_statements_are_not_allowed_in_an_async_function_block_1300", "'with' statements are not allowed in an async function block."),
8073
8062
  await_expressions_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules: diag(1308, ts.DiagnosticCategory.Error, "await_expressions_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules_1308", "'await' expressions are only allowed within async functions and at the top levels of modules."),
8074
8063
  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."),
@@ -8205,6 +8194,8 @@ var ts;
8205
8194
  The_import_meta_meta_property_is_not_allowed_in_files_which_will_build_into_CommonJS_output: diag(1470, ts.DiagnosticCategory.Error, "The_import_meta_meta_property_is_not_allowed_in_files_which_will_build_into_CommonJS_output_1470", "The 'import.meta' meta-property is not allowed in files which will build into CommonJS output."),
8206
8195
  Module_0_cannot_be_imported_using_this_construct_The_specifier_only_resolves_to_an_ES_module_which_cannot_be_imported_synchronously_Use_dynamic_import_instead: diag(1471, ts.DiagnosticCategory.Error, "Module_0_cannot_be_imported_using_this_construct_The_specifier_only_resolves_to_an_ES_module_which_c_1471", "Module '{0}' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead."),
8207
8196
  catch_or_finally_expected: diag(1472, ts.DiagnosticCategory.Error, "catch_or_finally_expected_1472", "'catch' or 'finally' expected."),
8197
+ An_import_declaration_can_only_be_used_at_the_top_level_of_a_module: diag(1473, ts.DiagnosticCategory.Error, "An_import_declaration_can_only_be_used_at_the_top_level_of_a_module_1473", "An import declaration can only be used at the top level of a module."),
8198
+ An_export_declaration_can_only_be_used_at_the_top_level_of_a_module: diag(1474, ts.DiagnosticCategory.Error, "An_export_declaration_can_only_be_used_at_the_top_level_of_a_module_1474", "An export declaration can only be used at the top level of a module."),
8208
8199
  The_types_of_0_are_incompatible_between_these_types: diag(2200, ts.DiagnosticCategory.Error, "The_types_of_0_are_incompatible_between_these_types_2200", "The types of '{0}' are incompatible between these types."),
8209
8200
  The_types_returned_by_0_are_incompatible_between_these_types: diag(2201, ts.DiagnosticCategory.Error, "The_types_returned_by_0_are_incompatible_between_these_types_2201", "The types returned by '{0}' are incompatible between these types."),
8210
8201
  Call_signature_return_types_0_and_1_are_incompatible: diag(2202, ts.DiagnosticCategory.Error, "Call_signature_return_types_0_and_1_are_incompatible_2202", "Call signature return types '{0}' and '{1}' are incompatible.", /*reportsUnnecessary*/ undefined, /*elidedInCompatabilityPyramid*/ true),
@@ -9625,6 +9616,9 @@ var ts;
9625
9616
  Add_all_missing_attributes: diag(95168, ts.DiagnosticCategory.Message, "Add_all_missing_attributes_95168", "Add all missing attributes"),
9626
9617
  Add_undefined_to_optional_property_type: diag(95169, ts.DiagnosticCategory.Message, "Add_undefined_to_optional_property_type_95169", "Add 'undefined' to optional property type"),
9627
9618
  Convert_named_imports_to_default_import: diag(95170, ts.DiagnosticCategory.Message, "Convert_named_imports_to_default_import_95170", "Convert named imports to default import"),
9619
+ Delete_unused_param_tag_0: diag(95171, ts.DiagnosticCategory.Message, "Delete_unused_param_tag_0_95171", "Delete unused '@param' tag '{0}'"),
9620
+ Delete_all_unused_param_tags: diag(95172, ts.DiagnosticCategory.Message, "Delete_all_unused_param_tags_95172", "Delete all unused '@param' tags"),
9621
+ Rename_param_tag_name_0_to_1: diag(95173, ts.DiagnosticCategory.Message, "Rename_param_tag_name_0_to_1_95173", "Rename '@param' tag name '{0}' to '{1}'"),
9628
9622
  No_value_exists_in_scope_for_the_shorthand_property_0_Either_declare_one_or_provide_an_initializer: diag(18004, ts.DiagnosticCategory.Error, "No_value_exists_in_scope_for_the_shorthand_property_0_Either_declare_one_or_provide_an_initializer_18004", "No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer."),
9629
9623
  Classes_may_not_have_a_field_named_constructor: diag(18006, ts.DiagnosticCategory.Error, "Classes_may_not_have_a_field_named_constructor_18006", "Classes may not have a field named 'constructor'."),
9630
9624
  JSX_expressions_may_not_use_the_comma_operator_Did_you_mean_to_write_an_array: diag(18007, ts.DiagnosticCategory.Error, "JSX_expressions_may_not_use_the_comma_operator_Did_you_mean_to_write_an_array_18007", "JSX expressions may not use the comma operator. Did you mean to write an array?"),
@@ -14125,6 +14119,10 @@ var ts;
14125
14119
  return getSourceFileOfNode(module.valueDeclaration || getNonAugmentationDeclaration(module));
14126
14120
  }
14127
14121
  ts.getSourceFileOfModule = getSourceFileOfModule;
14122
+ function isPlainJsFile(file, checkJs) {
14123
+ return !!file && (file.scriptKind === 1 /* JS */ || file.scriptKind === 2 /* JSX */) && !file.checkJsDirective && checkJs === undefined;
14124
+ }
14125
+ ts.isPlainJsFile = isPlainJsFile;
14128
14126
  function isStatementWithLocals(node) {
14129
14127
  switch (node.kind) {
14130
14128
  case 234 /* Block */:
@@ -41700,7 +41698,7 @@ var ts;
41700
41698
  result_4 = searchResult && searchResult.value;
41701
41699
  }
41702
41700
  else {
41703
- var candidate = ts.normalizePathAndParts(ts.combinePaths(initialLocationForSecondaryLookup, typeReferenceDirectiveName)).path;
41701
+ var candidate = normalizePathForCJSResolution(initialLocationForSecondaryLookup, typeReferenceDirectiveName).path;
41704
41702
  result_4 = nodeLoadModuleByRelativeName(Extensions.DtsOnly, candidate, /*onlyRecordFailures*/ false, moduleResolutionState, /*considerPackageJson*/ true);
41705
41703
  }
41706
41704
  return resolvedTypeScriptOnly(result_4);
@@ -42403,13 +42401,25 @@ var ts;
42403
42401
  return { value: resolvedValue && { resolved: resolvedValue, isExternalLibraryImport: true } };
42404
42402
  }
42405
42403
  else {
42406
- var _a = ts.normalizePathAndParts(ts.combinePaths(containingDirectory, moduleName)), candidate = _a.path, parts = _a.parts;
42404
+ var _a = normalizePathForCJSResolution(containingDirectory, moduleName), candidate = _a.path, parts = _a.parts;
42407
42405
  var resolved_2 = nodeLoadModuleByRelativeName(extensions, candidate, /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true);
42408
42406
  // Treat explicit "node_modules" import as an external library import.
42409
42407
  return resolved_2 && toSearchResult({ resolved: resolved_2, isExternalLibraryImport: ts.contains(parts, "node_modules") });
42410
42408
  }
42411
42409
  }
42412
42410
  }
42411
+ // If you import from "." inside a containing directory "/foo", the result of `normalizePath`
42412
+ // would be "/foo", but this loses the information that `foo` is a directory and we intended
42413
+ // to look inside of it. The Node CommonJS resolution algorithm doesn't call this out
42414
+ // (https://nodejs.org/api/modules.html#all-together), but it seems that module paths ending
42415
+ // in `.` are actually normalized to `./` before proceeding with the resolution algorithm.
42416
+ function normalizePathForCJSResolution(containingDirectory, moduleName) {
42417
+ var combined = ts.combinePaths(containingDirectory, moduleName);
42418
+ var parts = ts.getPathComponents(combined);
42419
+ var lastPart = ts.lastOrUndefined(parts);
42420
+ var path = lastPart === "." || lastPart === ".." ? ts.ensureTrailingDirectorySeparator(ts.normalizePath(combined)) : ts.normalizePath(combined);
42421
+ return { path: path, parts: parts };
42422
+ }
42413
42423
  function realPath(path, host, traceEnabled) {
42414
42424
  if (!host.realpath) {
42415
42425
  return path;
@@ -42451,7 +42461,13 @@ var ts;
42451
42461
  onlyRecordFailures = true;
42452
42462
  }
42453
42463
  }
42454
- return loadNodeModuleFromDirectory(extensions, candidate, onlyRecordFailures, state, considerPackageJson);
42464
+ // esm mode relative imports shouldn't do any directory lookups (either inside `package.json`
42465
+ // files or implicit `index.js`es). This is a notable depature from cjs norms, where `./foo/pkg`
42466
+ // could have been redirected by `./foo/pkg/package.json` to an arbitrary location!
42467
+ if (!(state.features & NodeResolutionFeatures.EsmMode)) {
42468
+ return loadNodeModuleFromDirectory(extensions, candidate, onlyRecordFailures, state, considerPackageJson);
42469
+ }
42470
+ return undefined;
42455
42471
  }
42456
42472
  /*@internal*/
42457
42473
  ts.nodeModulesPathPart = "/node_modules/";
@@ -42818,7 +42834,16 @@ var ts;
42818
42834
  // Even if extensions is DtsOnly, we can still look up a .ts file as a result of package.json "types"
42819
42835
  var nextExtensions = extensions === Extensions.DtsOnly ? Extensions.TypeScript : extensions;
42820
42836
  // Don't do package.json lookup recursively, because Node.js' package lookup doesn't.
42821
- return nodeLoadModuleByRelativeName(nextExtensions, candidate, onlyRecordFailures, state, /*considerPackageJson*/ false);
42837
+ // Disable `EsmMode` for the resolution of the package path for cjs-mode packages (so the `main` field can omit extensions)
42838
+ // (technically it only emits a deprecation warning in esm packages right now, but that's probably
42839
+ // enough to mean we don't need to support it)
42840
+ var features = state.features;
42841
+ if ((jsonContent === null || jsonContent === void 0 ? void 0 : jsonContent.type) !== "module") {
42842
+ state.features &= ~NodeResolutionFeatures.EsmMode;
42843
+ }
42844
+ var result = nodeLoadModuleByRelativeName(nextExtensions, candidate, onlyRecordFailures, state, /*considerPackageJson*/ false);
42845
+ state.features = features;
42846
+ return result;
42822
42847
  };
42823
42848
  var onlyRecordFailuresForPackageFile = packageFile ? !ts.directoryProbablyExists(ts.getDirectoryPath(packageFile), state.host) : undefined;
42824
42849
  var onlyRecordFailuresForIndex = onlyRecordFailures || !ts.directoryProbablyExists(candidate, state.host);
@@ -43163,6 +43188,14 @@ var ts;
43163
43188
  }
43164
43189
  var pathAndExtension = loadModuleFromFile(extensions, candidate, onlyRecordFailures, state) ||
43165
43190
  loadNodeModuleFromDirectoryWorker(extensions, candidate, onlyRecordFailures, state, packageInfo && packageInfo.packageJsonContent, packageInfo && packageInfo.versionPaths);
43191
+ if (!pathAndExtension && packageInfo
43192
+ && packageInfo.packageJsonContent.exports === undefined
43193
+ && packageInfo.packageJsonContent.main === undefined
43194
+ && state.features & NodeResolutionFeatures.EsmMode) {
43195
+ // EsmMode disables index lookup in `loadNodeModuleFromDirectoryWorker` generally, however non-relative package resolutions still assume
43196
+ // a default `index.js` entrypoint if no `main` or `exports` are present
43197
+ pathAndExtension = loadModuleFromFile(extensions, ts.combinePaths(candidate, "index.js"), onlyRecordFailures, state);
43198
+ }
43166
43199
  return withPackageId(packageInfo, pathAndExtension);
43167
43200
  };
43168
43201
  if (rest !== "") { // If "rest" is empty, we just did this search above.
@@ -46902,6 +46935,9 @@ var ts;
46902
46935
  CheckMode[CheckMode["SkipContextSensitive"] = 4] = "SkipContextSensitive";
46903
46936
  CheckMode[CheckMode["SkipGenericFunctions"] = 8] = "SkipGenericFunctions";
46904
46937
  CheckMode[CheckMode["IsForSignatureHelp"] = 16] = "IsForSignatureHelp";
46938
+ CheckMode[CheckMode["RestBindingElement"] = 32] = "RestBindingElement";
46939
+ // e.g. in `const { a, ...rest } = foo`, when checking the type of `foo` to determine the type of `rest`,
46940
+ // we need to preserve generic types instead of substituting them for constraints
46905
46941
  })(CheckMode || (CheckMode = {}));
46906
46942
  var SignatureCheckMode;
46907
46943
  (function (SignatureCheckMode) {
@@ -47954,13 +47990,13 @@ var ts;
47954
47990
  else { // error
47955
47991
  var isEitherEnum = !!(target.flags & 384 /* Enum */ || source.flags & 384 /* Enum */);
47956
47992
  var isEitherBlockScoped_1 = !!(target.flags & 2 /* BlockScopedVariable */ || source.flags & 2 /* BlockScopedVariable */);
47957
- var message = isEitherEnum
47958
- ? ts.Diagnostics.Enum_declarations_can_only_merge_with_namespace_or_other_enum_declarations
47959
- : isEitherBlockScoped_1
47960
- ? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0
47993
+ var message = isEitherEnum ? ts.Diagnostics.Enum_declarations_can_only_merge_with_namespace_or_other_enum_declarations
47994
+ : isEitherBlockScoped_1 ? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0
47961
47995
  : ts.Diagnostics.Duplicate_identifier_0;
47962
47996
  var sourceSymbolFile = source.declarations && ts.getSourceFileOfNode(source.declarations[0]);
47963
47997
  var targetSymbolFile = target.declarations && ts.getSourceFileOfNode(target.declarations[0]);
47998
+ var isSourcePlainJs = ts.isPlainJsFile(sourceSymbolFile, compilerOptions.checkJs);
47999
+ var isTargetPlainJs = ts.isPlainJsFile(targetSymbolFile, compilerOptions.checkJs);
47964
48000
  var symbolName_1 = symbolToString(source);
47965
48001
  // Collect top-level duplicate identifier errors into one mapping, so we can then merge their diagnostics if there are a bunch
47966
48002
  if (sourceSymbolFile && targetSymbolFile && amalgamatedDuplicates && !isEitherEnum && sourceSymbolFile !== targetSymbolFile) {
@@ -47972,12 +48008,16 @@ var ts;
47972
48008
  var conflictingSymbolInfo = ts.getOrUpdate(filesDuplicates.conflictingSymbols, symbolName_1, function () {
47973
48009
  return ({ isBlockScoped: isEitherBlockScoped_1, firstFileLocations: [], secondFileLocations: [] });
47974
48010
  });
47975
- addDuplicateLocations(conflictingSymbolInfo.firstFileLocations, source);
47976
- addDuplicateLocations(conflictingSymbolInfo.secondFileLocations, target);
48011
+ if (!isSourcePlainJs)
48012
+ addDuplicateLocations(conflictingSymbolInfo.firstFileLocations, source);
48013
+ if (!isTargetPlainJs)
48014
+ addDuplicateLocations(conflictingSymbolInfo.secondFileLocations, target);
47977
48015
  }
47978
48016
  else {
47979
- addDuplicateDeclarationErrorsForSymbols(source, message, symbolName_1, target);
47980
- addDuplicateDeclarationErrorsForSymbols(target, message, symbolName_1, source);
48017
+ if (!isSourcePlainJs)
48018
+ addDuplicateDeclarationErrorsForSymbols(source, message, symbolName_1, target);
48019
+ if (!isTargetPlainJs)
48020
+ addDuplicateDeclarationErrorsForSymbols(target, message, symbolName_1, source);
47981
48021
  }
47982
48022
  }
47983
48023
  return target;
@@ -48434,6 +48474,8 @@ var ts;
48434
48474
  // type parameters are visible in parameter list, return type and type parameter list
48435
48475
  ? lastLocation === location.type ||
48436
48476
  lastLocation.kind === 163 /* Parameter */ ||
48477
+ lastLocation.kind === 338 /* JSDocParameterTag */ ||
48478
+ lastLocation.kind === 339 /* JSDocReturnTag */ ||
48437
48479
  lastLocation.kind === 162 /* TypeParameter */
48438
48480
  // local types not visible outside the function body
48439
48481
  : false;
@@ -48693,9 +48735,9 @@ var ts;
48693
48735
  lastSelfReferenceLocation = location;
48694
48736
  }
48695
48737
  lastLocation = location;
48696
- location = ts.isJSDocTemplateTag(location) ?
48697
- ts.getEffectiveContainerForJSDocTemplateTag(location) || location.parent :
48698
- location.parent;
48738
+ location = ts.isJSDocTemplateTag(location) ? ts.getEffectiveContainerForJSDocTemplateTag(location) || location.parent :
48739
+ ts.isJSDocParameterTag(location) || ts.isJSDocReturnTag(location) ? ts.getHostSignatureFromJSDoc(location) || location.parent :
48740
+ location.parent;
48699
48741
  }
48700
48742
  // We just climbed up parents looking for the name, meaning that we started in a descendant node of `lastLocation`.
48701
48743
  // If `result === lastSelfReferenceLocation.symbol`, that means that we are somewhere inside `lastSelfReferenceLocation` looking up a name, and resolving to `lastLocation` itself.
@@ -49829,16 +49871,20 @@ var ts;
49829
49871
  return;
49830
49872
  }
49831
49873
  var host = ts.getJSDocHost(node);
49832
- if (host &&
49833
- ts.isExpressionStatement(host) &&
49834
- ts.isBinaryExpression(host.expression) &&
49835
- ts.getAssignmentDeclarationKind(host.expression) === 3 /* PrototypeProperty */) {
49836
- // X.prototype.m = /** @param {K} p */ function () { } <-- look for K on X's declaration
49874
+ if (host && ts.isExpressionStatement(host) && ts.isPrototypePropertyAssignment(host.expression)) {
49875
+ // /** @param {K} p */ X.prototype.m = function () { } <-- look for K on X's declaration
49837
49876
  var symbol = getSymbolOfNode(host.expression.left);
49838
49877
  if (symbol) {
49839
49878
  return getDeclarationOfJSPrototypeContainer(symbol);
49840
49879
  }
49841
49880
  }
49881
+ if (host && ts.isFunctionExpression(host) && ts.isPrototypePropertyAssignment(host.parent) && ts.isExpressionStatement(host.parent.parent)) {
49882
+ // X.prototype.m = /** @param {K} p */ function () { } <-- look for K on X's declaration
49883
+ var symbol = getSymbolOfNode(host.parent.left);
49884
+ if (symbol) {
49885
+ return getDeclarationOfJSPrototypeContainer(symbol);
49886
+ }
49887
+ }
49842
49888
  if (host && (ts.isObjectLiteralMethod(host) || ts.isPropertyAssignment(host)) &&
49843
49889
  ts.isBinaryExpression(host.parent.parent) &&
49844
49890
  ts.getAssignmentDeclarationKind(host.parent.parent) === 6 /* Prototype */) {
@@ -50367,8 +50413,15 @@ var ts;
50367
50413
  return res;
50368
50414
  }
50369
50415
  var candidates = ts.mapDefined(symbol.declarations, function (d) {
50370
- if (!ts.isAmbientModule(d) && d.parent && hasNonGlobalAugmentationExternalModuleSymbol(d.parent)) {
50371
- return getSymbolOfNode(d.parent);
50416
+ if (!ts.isAmbientModule(d) && d.parent) {
50417
+ // direct children of a module
50418
+ if (hasNonGlobalAugmentationExternalModuleSymbol(d.parent)) {
50419
+ return getSymbolOfNode(d.parent);
50420
+ }
50421
+ // export ='d member of an ambient module
50422
+ if (ts.isModuleBlock(d.parent) && d.parent.parent && resolveExternalModuleSymbol(getSymbolOfNode(d.parent.parent)) === symbol) {
50423
+ return getSymbolOfNode(d.parent.parent);
50424
+ }
50372
50425
  }
50373
50426
  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)) {
50374
50427
  if (ts.isModuleExportsAccessExpression(d.parent.left) || ts.isExportsIdentifier(d.parent.left.expression)) {
@@ -54325,9 +54378,12 @@ var ts;
54325
54378
  }
54326
54379
  // Return the type of a binding element parent. We check SymbolLinks first to see if a type has been
54327
54380
  // assigned by contextual typing.
54328
- function getTypeForBindingElementParent(node) {
54381
+ function getTypeForBindingElementParent(node, checkMode) {
54382
+ if (checkMode !== 0 /* Normal */) {
54383
+ return getTypeForVariableLikeDeclaration(node, /*includeOptionality*/ false, checkMode);
54384
+ }
54329
54385
  var symbol = getSymbolOfNode(node);
54330
- return symbol && getSymbolLinks(symbol).type || getTypeForVariableLikeDeclaration(node, /*includeOptionality*/ false);
54386
+ return symbol && getSymbolLinks(symbol).type || getTypeForVariableLikeDeclaration(node, /*includeOptionality*/ false, checkMode);
54331
54387
  }
54332
54388
  function getRestType(source, properties, symbol) {
54333
54389
  source = filterType(source, function (t) { return !(t.flags & 98304 /* Nullable */); });
@@ -54445,7 +54501,8 @@ var ts;
54445
54501
  }
54446
54502
  /** Return the inferred type for a binding element */
54447
54503
  function getTypeForBindingElement(declaration) {
54448
- var parentType = getTypeForBindingElementParent(declaration.parent.parent);
54504
+ var checkMode = declaration.dotDotDotToken ? 32 /* RestBindingElement */ : 0 /* Normal */;
54505
+ var parentType = getTypeForBindingElementParent(declaration.parent.parent, checkMode);
54449
54506
  return parentType && getBindingElementTypeFromParentType(declaration, parentType);
54450
54507
  }
54451
54508
  function getBindingElementTypeFromParentType(declaration, parentType) {
@@ -54517,9 +54574,9 @@ var ts;
54517
54574
  if (ts.getEffectiveTypeAnnotationNode(ts.walkUpBindingElementsAndPatterns(declaration))) {
54518
54575
  // In strict null checking mode, if a default value of a non-undefined type is specified, remove
54519
54576
  // undefined from the final type.
54520
- return strictNullChecks && !(getFalsyFlags(checkDeclarationInitializer(declaration)) & 32768 /* Undefined */) ? getNonUndefinedType(type) : type;
54577
+ return strictNullChecks && !(getFalsyFlags(checkDeclarationInitializer(declaration, 0 /* Normal */)) & 32768 /* Undefined */) ? getNonUndefinedType(type) : type;
54521
54578
  }
54522
- return widenTypeInferredFromInitializer(declaration, getUnionType([getNonUndefinedType(type), checkDeclarationInitializer(declaration)], 2 /* Subtype */));
54579
+ return widenTypeInferredFromInitializer(declaration, getUnionType([getNonUndefinedType(type), checkDeclarationInitializer(declaration, 0 /* Normal */)], 2 /* Subtype */));
54523
54580
  }
54524
54581
  function getTypeForDeclarationFromJSDocComment(declaration) {
54525
54582
  var jsdocType = ts.getJSDocType(declaration);
@@ -54542,11 +54599,11 @@ var ts;
54542
54599
  return strictNullChecks && isOptional ? getOptionalType(type, isProperty) : type;
54543
54600
  }
54544
54601
  // Return the inferred type for a variable, parameter, or property declaration
54545
- function getTypeForVariableLikeDeclaration(declaration, includeOptionality) {
54602
+ function getTypeForVariableLikeDeclaration(declaration, includeOptionality, checkMode) {
54546
54603
  // A variable declared in a for..in statement is of type string, or of type keyof T when the
54547
54604
  // right hand expression is of a type parameter type.
54548
54605
  if (ts.isVariableDeclaration(declaration) && declaration.parent.parent.kind === 242 /* ForInStatement */) {
54549
- var indexType = getIndexType(getNonNullableTypeIfNeeded(checkExpression(declaration.parent.parent.expression)));
54606
+ var indexType = getIndexType(getNonNullableTypeIfNeeded(checkExpression(declaration.parent.parent.expression, /*checkMode*/ checkMode)));
54550
54607
  return indexType.flags & (262144 /* TypeParameter */ | 4194304 /* Index */) ? getExtractStringType(indexType) : stringType;
54551
54608
  }
54552
54609
  if (ts.isVariableDeclaration(declaration) && declaration.parent.parent.kind === 243 /* ForOfStatement */) {
@@ -54601,12 +54658,9 @@ var ts;
54601
54658
  }
54602
54659
  }
54603
54660
  if (ts.isInJSFile(declaration)) {
54604
- var typeTag = ts.getJSDocType(func);
54605
- if (typeTag && ts.isFunctionTypeNode(typeTag)) {
54606
- var signature = getSignatureFromDeclaration(typeTag);
54607
- var pos = func.parameters.indexOf(declaration);
54608
- return declaration.dotDotDotToken ? getRestTypeAtPosition(signature, pos) : getTypeAtPosition(signature, pos);
54609
- }
54661
+ var type_1 = getParameterTypeOfTypeTag(func, declaration);
54662
+ if (type_1)
54663
+ return type_1;
54610
54664
  }
54611
54665
  // Use contextual parameter type if one is available
54612
54666
  var type = declaration.symbol.escapedName === "this" /* This */ ? getContextualThisParameterType(func) : getContextuallyTypedParameterType(declaration);
@@ -54623,7 +54677,7 @@ var ts;
54623
54677
  return containerObjectType;
54624
54678
  }
54625
54679
  }
54626
- var type = widenTypeInferredFromInitializer(declaration, checkDeclarationInitializer(declaration));
54680
+ var type = widenTypeInferredFromInitializer(declaration, checkDeclarationInitializer(declaration, checkMode));
54627
54681
  return addOptionality(type, isProperty, isOptional);
54628
54682
  }
54629
54683
  if (ts.isPropertyDeclaration(declaration) && (noImplicitAny || ts.isInJSFile(declaration))) {
@@ -54995,7 +55049,7 @@ var ts;
54995
55049
  // contextual type or, if the element itself is a binding pattern, with the type implied by that binding
54996
55050
  // pattern.
54997
55051
  var contextualType = ts.isBindingPattern(element.name) ? getTypeFromBindingPattern(element.name, /*includePatternInType*/ true, /*reportErrors*/ false) : unknownType;
54998
- return addOptionality(widenTypeInferredFromInitializer(element, checkDeclarationInitializer(element, contextualType)));
55052
+ return addOptionality(widenTypeInferredFromInitializer(element, checkDeclarationInitializer(element, 0 /* Normal */, contextualType)));
54999
55053
  }
55000
55054
  if (ts.isBindingPattern(element.name)) {
55001
55055
  return getTypeFromBindingPattern(element.name, includePatternInType, reportErrors);
@@ -55084,7 +55138,7 @@ var ts;
55084
55138
  // binding pattern [x, s = ""]. Because the contextual type is a tuple type, the resulting type of [1, "one"] is the
55085
55139
  // tuple type [number, string]. Thus, the type inferred for 'x' is number and the type inferred for 's' is string.
55086
55140
  function getWidenedTypeForVariableLikeDeclaration(declaration, reportErrors) {
55087
- return widenTypeForVariableLikeDeclaration(getTypeForVariableLikeDeclaration(declaration, /*includeOptionality*/ true), declaration, reportErrors);
55141
+ return widenTypeForVariableLikeDeclaration(getTypeForVariableLikeDeclaration(declaration, /*includeOptionality*/ true, 0 /* Normal */), declaration, reportErrors);
55088
55142
  }
55089
55143
  function isGlobalSymbolConstructor(node) {
55090
55144
  var symbol = getSymbolOfNode(node);
@@ -55173,9 +55227,9 @@ var ts;
55173
55227
  if (typeNode === undefined) {
55174
55228
  return useUnknownInCatchVariables ? unknownType : anyType;
55175
55229
  }
55176
- var type_1 = getTypeOfNode(typeNode);
55230
+ var type_2 = getTypeOfNode(typeNode);
55177
55231
  // an errorType will make `checkTryStatement` issue an error
55178
- return isTypeAny(type_1) || type_1 === unknownType ? type_1 : errorType;
55232
+ return isTypeAny(type_2) || type_2 === unknownType ? type_2 : errorType;
55179
55233
  }
55180
55234
  // Handle export default expressions
55181
55235
  if (ts.isSourceFile(declaration) && ts.isJsonSourceFile(declaration)) {
@@ -55313,10 +55367,12 @@ var ts;
55313
55367
  if (writing === void 0) { writing = false; }
55314
55368
  var getter = ts.getDeclarationOfKind(symbol, 171 /* GetAccessor */);
55315
55369
  var setter = ts.getDeclarationOfKind(symbol, 172 /* SetAccessor */);
55316
- var setterType = getAnnotatedAccessorType(setter);
55317
55370
  // For write operations, prioritize type annotations on the setter
55318
- if (writing && setterType) {
55319
- return instantiateTypeIfNeeded(setterType, symbol);
55371
+ if (writing) {
55372
+ var setterType_1 = getAnnotatedAccessorType(setter);
55373
+ if (setterType_1) {
55374
+ return instantiateTypeIfNeeded(setterType_1, symbol);
55375
+ }
55320
55376
  }
55321
55377
  // Else defer to the getter type
55322
55378
  if (getter && ts.isInJSFile(getter)) {
@@ -55331,6 +55387,7 @@ var ts;
55331
55387
  return instantiateTypeIfNeeded(getterType, symbol);
55332
55388
  }
55333
55389
  // If the user didn't specify a return type, try to use the set-accessor's parameter type.
55390
+ var setterType = getAnnotatedAccessorType(setter);
55334
55391
  if (setterType) {
55335
55392
  return setterType;
55336
55393
  }
@@ -55401,11 +55458,11 @@ var ts;
55401
55458
  return errorType;
55402
55459
  }
55403
55460
  var exportEquals = getMergedSymbol(symbol.exports.get("export=" /* ExportEquals */));
55404
- var type_2 = getWidenedTypeForAssignmentDeclaration(exportEquals, exportEquals === resolvedModule ? undefined : resolvedModule);
55461
+ var type_3 = getWidenedTypeForAssignmentDeclaration(exportEquals, exportEquals === resolvedModule ? undefined : resolvedModule);
55405
55462
  if (!popTypeResolution()) {
55406
55463
  return reportCircularityError(symbol);
55407
55464
  }
55408
- return type_2;
55465
+ return type_3;
55409
55466
  }
55410
55467
  }
55411
55468
  var type = createObjectType(16 /* Anonymous */, symbol);
@@ -57637,10 +57694,10 @@ var ts;
57637
57694
  var baseTypes = [];
57638
57695
  var different = false;
57639
57696
  for (var _i = 0, types_7 = types; _i < types_7.length; _i++) {
57640
- var type_3 = types_7[_i];
57641
- var baseType = getBaseConstraint(type_3);
57697
+ var type_4 = types_7[_i];
57698
+ var baseType = getBaseConstraint(type_4);
57642
57699
  if (baseType) {
57643
- if (baseType !== type_3) {
57700
+ if (baseType !== type_4) {
57644
57701
  different = true;
57645
57702
  }
57646
57703
  baseTypes.push(baseType);
@@ -58353,6 +58410,13 @@ var ts;
58353
58410
  var typeTag = ts.getJSDocTypeTag(node);
58354
58411
  return (typeTag === null || typeTag === void 0 ? void 0 : typeTag.typeExpression) && getSingleCallSignature(getTypeFromTypeNode(typeTag.typeExpression));
58355
58412
  }
58413
+ function getParameterTypeOfTypeTag(func, parameter) {
58414
+ var signature = getSignatureOfTypeTag(func);
58415
+ if (!signature)
58416
+ return undefined;
58417
+ var pos = func.parameters.indexOf(parameter);
58418
+ return parameter.dotDotDotToken ? getRestTypeAtPosition(signature, pos) : getTypeAtPosition(signature, pos);
58419
+ }
58356
58420
  function getReturnTypeOfTypeTag(node) {
58357
58421
  var signature = getSignatureOfTypeTag(node);
58358
58422
  return signature && getReturnTypeOfSignature(signature);
@@ -63092,9 +63156,11 @@ var ts;
63092
63156
  isEnumTypeRelatedTo(getParentOfSymbol(source.symbol), getParentOfSymbol(target.symbol), errorReporter))
63093
63157
  return true;
63094
63158
  }
63095
- if (s & 32768 /* Undefined */ && (!strictNullChecks || t & (32768 /* Undefined */ | 16384 /* Void */)))
63159
+ // In non-strictNullChecks mode, `undefined` and `null` are assignable to anything except `never`.
63160
+ // Since unions and intersections may reduce to `never`, we exclude them here.
63161
+ if (s & 32768 /* Undefined */ && (!strictNullChecks && !(t & 3145728 /* UnionOrIntersection */) || t & (32768 /* Undefined */ | 16384 /* Void */)))
63096
63162
  return true;
63097
- if (s & 65536 /* Null */ && (!strictNullChecks || t & 65536 /* Null */))
63163
+ if (s & 65536 /* Null */ && (!strictNullChecks && !(t & 3145728 /* UnionOrIntersection */) || t & 65536 /* Null */))
63098
63164
  return true;
63099
63165
  if (s & 524288 /* Object */ && t & 67108864 /* NonPrimitive */)
63100
63166
  return true;
@@ -64550,6 +64616,11 @@ var ts;
64550
64616
  }
64551
64617
  if (ts.getObjectFlags(source) & 4 /* Reference */ && ts.getObjectFlags(target) & 4 /* Reference */ && source.target === target.target &&
64552
64618
  !isTupleType(source) && !(ts.getObjectFlags(source) & 4096 /* MarkerType */ || ts.getObjectFlags(target) & 4096 /* MarkerType */)) {
64619
+ // When strictNullChecks is disabled, the element type of the empty array literal is undefinedWideningType,
64620
+ // and an empty array literal wouldn't be assignable to a `never[]` without this check.
64621
+ if (isEmptyArrayLiteralType(source)) {
64622
+ return -1 /* True */;
64623
+ }
64553
64624
  // We have type references to the same generic type, and the type references are not marker
64554
64625
  // type references (which are intended by be compared structurally). Obtain the variance
64555
64626
  // information for the type parameters and relate the type arguments accordingly.
@@ -64856,6 +64927,15 @@ var ts;
64856
64927
  }
64857
64928
  return 0 /* False */;
64858
64929
  }
64930
+ // Ensure {readonly a: whatever} is not a subtype of {a: whatever},
64931
+ // while {a: whatever} is a subtype of {readonly a: whatever}.
64932
+ // This ensures the subtype relationship is ordered, and preventing declaration order
64933
+ // from deciding which type "wins" in union subtype reduction.
64934
+ // They're still assignable to one another, since `readonly` doesn't affect assignability.
64935
+ if ((relation === subtypeRelation || relation === strictSubtypeRelation) &&
64936
+ !!(sourcePropFlags & 64 /* Readonly */) && !(targetPropFlags & 64 /* Readonly */)) {
64937
+ return 0 /* False */;
64938
+ }
64859
64939
  // If the target comes from a partial union prop, allow `undefined` in the target type
64860
64940
  var related = isPropertySymbolTypeRelated(sourceProp, targetProp, getTypeOfSourceProperty, reportErrors, intersectionState);
64861
64941
  if (!related) {
@@ -69888,12 +69968,16 @@ var ts;
69888
69968
  function isGenericTypeWithoutNullableConstraint(type) {
69889
69969
  return !!(type.flags & 465829888 /* Instantiable */ && !maybeTypeOfKind(getBaseConstraintOrType(type), 98304 /* Nullable */));
69890
69970
  }
69891
- function hasNonBindingPatternContextualTypeWithNoGenericTypes(node) {
69971
+ function hasContextualTypeWithNoGenericTypes(node, checkMode) {
69892
69972
  // Computing the contextual type for a child of a JSX element involves resolving the type of the
69893
69973
  // element's tag name, so we exclude that here to avoid circularities.
69974
+ // If check mode has `CheckMode.RestBindingElement`, we skip binding pattern contextual types,
69975
+ // as we want the type of a rest element to be generic when possible.
69894
69976
  var contextualType = (ts.isIdentifier(node) || ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node)) &&
69895
69977
  !((ts.isJsxOpeningElement(node.parent) || ts.isJsxSelfClosingElement(node.parent)) && node.parent.tagName === node) &&
69896
- getContextualType(node, 8 /* SkipBindingPatterns */);
69978
+ (checkMode && checkMode & 32 /* RestBindingElement */ ?
69979
+ getContextualType(node, 8 /* SkipBindingPatterns */)
69980
+ : getContextualType(node));
69897
69981
  return contextualType && !isGenericType(contextualType);
69898
69982
  }
69899
69983
  function getNarrowableTypeForReference(type, reference, checkMode) {
@@ -69906,7 +69990,7 @@ var ts;
69906
69990
  // 'string | undefined' to give control flow analysis the opportunity to narrow to type 'string'.
69907
69991
  var substituteConstraints = !(checkMode && checkMode & 2 /* Inferential */) &&
69908
69992
  someType(type, isGenericTypeWithUnionConstraint) &&
69909
- (isConstraintPosition(type, reference) || hasNonBindingPatternContextualTypeWithNoGenericTypes(reference));
69993
+ (isConstraintPosition(type, reference) || hasContextualTypeWithNoGenericTypes(reference, checkMode));
69910
69994
  return substituteConstraints ? mapType(type, function (t) { return t.flags & 465829888 /* Instantiable */ && !isMappedTypeGenericIndexedAccess(t) ? getBaseConstraintOrType(t) : t; }) : type;
69911
69995
  }
69912
69996
  function isExportOrExportExpression(location) {
@@ -69974,7 +70058,7 @@ var ts;
69974
70058
  var links = getNodeLinks(location);
69975
70059
  if (!(links.flags & 268435456 /* InCheckIdentifier */)) {
69976
70060
  links.flags |= 268435456 /* InCheckIdentifier */;
69977
- var parentType = getTypeForBindingElementParent(parent);
70061
+ var parentType = getTypeForBindingElementParent(parent, 0 /* Normal */);
69978
70062
  links.flags &= ~268435456 /* InCheckIdentifier */;
69979
70063
  if (parentType && parentType.flags & 1048576 /* Union */ && !(parent.kind === 163 /* Parameter */ && isSymbolAssigned(symbol))) {
69980
70064
  var pattern = declaration.parent;
@@ -70827,7 +70911,7 @@ var ts;
70827
70911
  var parent = declaration.parent.parent;
70828
70912
  var name = declaration.propertyName || declaration.name;
70829
70913
  var parentType = getContextualTypeForVariableLikeDeclaration(parent) ||
70830
- parent.kind !== 202 /* BindingElement */ && parent.initializer && checkDeclarationInitializer(parent);
70914
+ parent.kind !== 202 /* BindingElement */ && parent.initializer && checkDeclarationInitializer(parent, declaration.dotDotDotToken ? 32 /* RestBindingElement */ : 0 /* Normal */);
70831
70915
  if (!parentType || ts.isBindingPattern(name) || ts.isComputedNonLiteralName(name))
70832
70916
  return undefined;
70833
70917
  if (parent.name.kind === 201 /* ArrayBindingPattern */) {
@@ -75538,8 +75622,8 @@ var ts;
75538
75622
  if (hasDefaultOnly && type && !isErrorType(type)) {
75539
75623
  var synthType = type;
75540
75624
  if (!synthType.defaultOnlyType) {
75541
- var type_4 = createDefaultPropertyWrapperForModule(symbol, originalSymbol);
75542
- synthType.defaultOnlyType = type_4;
75625
+ var type_5 = createDefaultPropertyWrapperForModule(symbol, originalSymbol);
75626
+ synthType.defaultOnlyType = type_5;
75543
75627
  }
75544
75628
  return synthType.defaultOnlyType;
75545
75629
  }
@@ -75993,7 +76077,7 @@ var ts;
75993
76077
  var links = getSymbolLinks(parameter);
75994
76078
  if (!links.type) {
75995
76079
  var declaration = parameter.valueDeclaration;
75996
- links.type = type || getWidenedTypeForVariableLikeDeclaration(declaration, /*includeOptionality*/ true);
76080
+ links.type = type || getWidenedTypeForVariableLikeDeclaration(declaration, /*reportErrors*/ true);
75997
76081
  if (declaration.name.kind !== 79 /* Identifier */) {
75998
76082
  // if inference didn't come up with anything but unknown, fall back to the binding pattern if present.
75999
76083
  if (links.type === unknownType) {
@@ -76266,12 +76350,12 @@ var ts;
76266
76350
  var witnesses = getSwitchClauseTypeOfWitnesses(node, /*retainDefault*/ false);
76267
76351
  // notEqualFacts states that the type of the switched value is not equal to every type in the switch.
76268
76352
  var notEqualFacts_1 = getFactsFromTypeofSwitch(0, 0, witnesses, /*hasDefault*/ true);
76269
- var type_5 = getBaseConstraintOfType(operandType) || operandType;
76353
+ var type_6 = getBaseConstraintOfType(operandType) || operandType;
76270
76354
  // Take any/unknown as a special condition. Or maybe we could change `type` to a union containing all primitive types.
76271
- if (type_5.flags & 3 /* AnyOrUnknown */) {
76355
+ if (type_6.flags & 3 /* AnyOrUnknown */) {
76272
76356
  return (556800 /* AllTypeofNE */ & notEqualFacts_1) === 556800 /* AllTypeofNE */;
76273
76357
  }
76274
- return !!(filterType(type_5, function (t) { return (getTypeFacts(t) & notEqualFacts_1) === notEqualFacts_1; }).flags & 131072 /* Never */);
76358
+ return !!(filterType(type_6, function (t) { return (getTypeFacts(t) & notEqualFacts_1) === notEqualFacts_1; }).flags & 131072 /* Never */);
76275
76359
  }
76276
76360
  var type = getTypeOfExpression(node.expression);
76277
76361
  if (!isLiteralType(type)) {
@@ -77724,11 +77808,11 @@ var ts;
77724
77808
  }
77725
77809
  }
77726
77810
  function checkExpressionCached(node, checkMode) {
77811
+ if (checkMode && checkMode !== 0 /* Normal */) {
77812
+ return checkExpression(node, checkMode);
77813
+ }
77727
77814
  var links = getNodeLinks(node);
77728
77815
  if (!links.resolvedType) {
77729
- if (checkMode && checkMode !== 0 /* Normal */) {
77730
- return checkExpression(node, checkMode);
77731
- }
77732
77816
  // When computing a type that we're going to cache, we need to ignore any ongoing control flow
77733
77817
  // analysis because variables may have transient types in indeterminable states. Moving flowLoopStart
77734
77818
  // to the top of the stack ensures all transient types are computed from a known point.
@@ -77748,10 +77832,12 @@ var ts;
77748
77832
  node.kind === 228 /* AsExpression */ ||
77749
77833
  ts.isJSDocTypeAssertion(node);
77750
77834
  }
77751
- function checkDeclarationInitializer(declaration, contextualType) {
77835
+ function checkDeclarationInitializer(declaration, checkMode, contextualType) {
77752
77836
  var initializer = ts.getEffectiveInitializer(declaration);
77753
77837
  var type = getQuickTypeOfExpression(initializer) ||
77754
- (contextualType ? checkExpressionWithContextualType(initializer, contextualType, /*inferenceContext*/ undefined, 0 /* Normal */) : checkExpressionCached(initializer));
77838
+ (contextualType ?
77839
+ checkExpressionWithContextualType(initializer, contextualType, /*inferenceContext*/ undefined, checkMode || 0 /* Normal */)
77840
+ : checkExpressionCached(initializer, checkMode));
77755
77841
  return ts.isParameter(declaration) && declaration.name.kind === 201 /* ArrayBindingPattern */ &&
77756
77842
  isTupleType(type) && !type.target.hasRestElement && getTypeReferenceArity(type) < declaration.name.elements.length ?
77757
77843
  padTupleType(type, declaration.name) : type;
@@ -78391,6 +78477,7 @@ var ts;
78391
78477
  }
78392
78478
  }
78393
78479
  checkTypeParameters(ts.getEffectiveTypeParameterDeclarations(node));
78480
+ checkUnmatchedJSDocParameters(node);
78394
78481
  ts.forEach(node.parameters, checkParameter);
78395
78482
  // TODO(rbuckton): Should we start checking JSDoc types?
78396
78483
  if (node.type) {
@@ -79962,31 +80049,6 @@ var ts;
79962
80049
  }
79963
80050
  function checkJSDocParameterTag(node) {
79964
80051
  checkSourceElement(node.typeExpression);
79965
- if (!ts.getParameterSymbolFromJSDoc(node)) {
79966
- var decl = ts.getHostSignatureFromJSDoc(node);
79967
- // don't issue an error for invalid hosts -- just functions --
79968
- // and give a better error message when the host function mentions `arguments`
79969
- // but the tag doesn't have an array type
79970
- if (decl) {
79971
- var i = ts.getJSDocTags(decl).filter(ts.isJSDocParameterTag).indexOf(node);
79972
- if (i > -1 && i < decl.parameters.length && ts.isBindingPattern(decl.parameters[i].name)) {
79973
- return;
79974
- }
79975
- if (!containsArgumentsReference(decl)) {
79976
- if (ts.isQualifiedName(node.name)) {
79977
- error(node.name, ts.Diagnostics.Qualified_name_0_is_not_allowed_without_a_leading_param_object_1, ts.entityNameToString(node.name), ts.entityNameToString(node.name.left));
79978
- }
79979
- else {
79980
- error(node.name, ts.Diagnostics.JSDoc_param_tag_has_name_0_but_there_is_no_parameter_with_that_name, ts.idText(node.name));
79981
- }
79982
- }
79983
- else if (ts.findLast(ts.getJSDocTags(decl), ts.isJSDocParameterTag) === node &&
79984
- node.typeExpression && node.typeExpression.type &&
79985
- !isArrayType(getTypeFromTypeNode(node.typeExpression.type))) {
79986
- error(node.name, ts.Diagnostics.JSDoc_param_tag_has_name_0_but_there_is_no_parameter_with_that_name_It_would_match_arguments_if_it_had_an_array_type, ts.idText(node.name.kind === 160 /* QualifiedName */ ? node.name.right : node.name));
79987
- }
79988
- }
79989
- }
79990
80052
  }
79991
80053
  function checkJSDocPropertyTag(node) {
79992
80054
  checkSourceElement(node.typeExpression);
@@ -80688,7 +80750,8 @@ var ts;
80688
80750
  }
80689
80751
  // check private/protected variable access
80690
80752
  var parent = node.parent.parent;
80691
- var parentType = getTypeForBindingElementParent(parent);
80753
+ var parentCheckMode = node.dotDotDotToken ? 32 /* RestBindingElement */ : 0 /* Normal */;
80754
+ var parentType = getTypeForBindingElementParent(parent, parentCheckMode);
80692
80755
  var name = node.propertyName || node.name;
80693
80756
  if (parentType && !ts.isBindingPattern(name)) {
80694
80757
  var exprType = getLiteralTypeFromPropertyName(name);
@@ -81927,7 +81990,7 @@ var ts;
81927
81990
  var declaration = catchClause.variableDeclaration;
81928
81991
  var typeNode = ts.getEffectiveTypeAnnotationNode(ts.getRootDeclaration(declaration));
81929
81992
  if (typeNode) {
81930
- var type = getTypeForVariableLikeDeclaration(declaration, /*includeOptionality*/ false);
81993
+ var type = getTypeForVariableLikeDeclaration(declaration, /*includeOptionality*/ false, 0 /* Normal */);
81931
81994
  if (type && !(type.flags & 3 /* AnyOrUnknown */)) {
81932
81995
  grammarErrorOnFirstToken(typeNode, ts.Diagnostics.Catch_clause_variable_type_annotation_must_be_any_or_unknown_if_specified);
81933
81996
  }
@@ -82058,6 +82121,45 @@ var ts;
82058
82121
  error(name, ts.Diagnostics.Class_name_cannot_be_Object_when_targeting_ES5_with_module_0, ts.ModuleKind[moduleKind]); // https://github.com/Microsoft/TypeScript/issues/17494
82059
82122
  }
82060
82123
  }
82124
+ function checkUnmatchedJSDocParameters(node) {
82125
+ var jsdocParameters = ts.filter(ts.getJSDocTags(node), ts.isJSDocParameterTag);
82126
+ if (!ts.length(jsdocParameters))
82127
+ return;
82128
+ var isJs = ts.isInJSFile(node);
82129
+ var parameters = new ts.Set();
82130
+ var excludedParameters = new ts.Set();
82131
+ ts.forEach(node.parameters, function (_a, index) {
82132
+ var name = _a.name;
82133
+ if (ts.isIdentifier(name)) {
82134
+ parameters.add(name.escapedText);
82135
+ }
82136
+ if (ts.isBindingPattern(name)) {
82137
+ excludedParameters.add(index);
82138
+ }
82139
+ });
82140
+ var containsArguments = containsArgumentsReference(node);
82141
+ if (containsArguments) {
82142
+ var lastJSDocParam = ts.lastOrUndefined(jsdocParameters);
82143
+ if (lastJSDocParam && ts.isIdentifier(lastJSDocParam.name) && lastJSDocParam.typeExpression &&
82144
+ lastJSDocParam.typeExpression.type && !parameters.has(lastJSDocParam.name.escapedText) && !isArrayType(getTypeFromTypeNode(lastJSDocParam.typeExpression.type))) {
82145
+ errorOrSuggestion(isJs, lastJSDocParam.name, ts.Diagnostics.JSDoc_param_tag_has_name_0_but_there_is_no_parameter_with_that_name_It_would_match_arguments_if_it_had_an_array_type, ts.idText(lastJSDocParam.name));
82146
+ }
82147
+ }
82148
+ else {
82149
+ ts.forEach(jsdocParameters, function (_a, index) {
82150
+ var name = _a.name;
82151
+ if (excludedParameters.has(index) || ts.isIdentifier(name) && parameters.has(name.escapedText)) {
82152
+ return;
82153
+ }
82154
+ if (ts.isQualifiedName(name)) {
82155
+ errorOrSuggestion(isJs, name, ts.Diagnostics.Qualified_name_0_is_not_allowed_without_a_leading_param_object_1, ts.entityNameToString(name), ts.entityNameToString(name.left));
82156
+ }
82157
+ else {
82158
+ errorOrSuggestion(isJs, name, ts.Diagnostics.JSDoc_param_tag_has_name_0_but_there_is_no_parameter_with_that_name, ts.idText(name));
82159
+ }
82160
+ });
82161
+ }
82162
+ }
82061
82163
  /**
82062
82164
  * Check each type parameter and check that type parameters have no duplicate type parameter declarations
82063
82165
  */
@@ -83033,7 +83135,7 @@ var ts;
83033
83135
  var isAmbientExternalModule = ts.isAmbientModule(node);
83034
83136
  var contextErrorMessage = isAmbientExternalModule
83035
83137
  ? ts.Diagnostics.An_ambient_module_declaration_is_only_allowed_at_the_top_level_in_a_file
83036
- : ts.Diagnostics.A_namespace_declaration_is_only_allowed_in_a_namespace_or_module;
83138
+ : ts.Diagnostics.A_namespace_declaration_is_only_allowed_at_the_top_level_of_a_namespace_or_module;
83037
83139
  if (checkGrammarModuleElementContext(node, contextErrorMessage)) {
83038
83140
  // If we hit a module declaration in an illegal context, just bail out to avoid cascading errors.
83039
83141
  return;
@@ -83266,6 +83368,9 @@ var ts;
83266
83368
  var name = ts.idText(node.kind === 269 /* ImportSpecifier */ ? node.propertyName || node.name : node.name);
83267
83369
  addTypeOnlyDeclarationRelatedInfo(error(node, message, name), isType ? undefined : typeOnlyAlias, name);
83268
83370
  }
83371
+ if (isType && node.kind === 264 /* ImportEqualsDeclaration */ && ts.hasEffectiveModifier(node, 1 /* Export */)) {
83372
+ error(node, ts.Diagnostics.Cannot_use_export_import_on_a_type_or_type_only_namespace_when_the_isolatedModules_flag_is_provided);
83373
+ }
83269
83374
  break;
83270
83375
  }
83271
83376
  case 274 /* ExportSpecifier */: {
@@ -83349,7 +83454,7 @@ var ts;
83349
83454
  }
83350
83455
  }
83351
83456
  function checkImportDeclaration(node) {
83352
- if (checkGrammarModuleElementContext(node, ts.Diagnostics.An_import_declaration_can_only_be_used_in_a_namespace_or_module)) {
83457
+ if (checkGrammarModuleElementContext(node, ts.isInJSFile(node) ? ts.Diagnostics.An_import_declaration_can_only_be_used_at_the_top_level_of_a_module : ts.Diagnostics.An_import_declaration_can_only_be_used_at_the_top_level_of_a_namespace_or_module)) {
83353
83458
  // If we hit an import declaration in an illegal context, just bail out to avoid cascading errors.
83354
83459
  return;
83355
83460
  }
@@ -83382,7 +83487,7 @@ var ts;
83382
83487
  checkAssertClause(node);
83383
83488
  }
83384
83489
  function checkImportEqualsDeclaration(node) {
83385
- if (checkGrammarModuleElementContext(node, ts.Diagnostics.An_import_declaration_can_only_be_used_in_a_namespace_or_module)) {
83490
+ if (checkGrammarModuleElementContext(node, ts.isInJSFile(node) ? ts.Diagnostics.An_import_declaration_can_only_be_used_at_the_top_level_of_a_module : ts.Diagnostics.An_import_declaration_can_only_be_used_at_the_top_level_of_a_namespace_or_module)) {
83386
83491
  // If we hit an import declaration in an illegal context, just bail out to avoid cascading errors.
83387
83492
  return;
83388
83493
  }
@@ -83419,7 +83524,7 @@ var ts;
83419
83524
  }
83420
83525
  }
83421
83526
  function checkExportDeclaration(node) {
83422
- if (checkGrammarModuleElementContext(node, ts.Diagnostics.An_export_declaration_can_only_be_used_in_a_module)) {
83527
+ if (checkGrammarModuleElementContext(node, ts.isInJSFile(node) ? ts.Diagnostics.An_export_declaration_can_only_be_used_at_the_top_level_of_a_module : ts.Diagnostics.An_export_declaration_can_only_be_used_at_the_top_level_of_a_namespace_or_module)) {
83423
83528
  // If we hit an export in an illegal context, just bail out to avoid cascading errors.
83424
83529
  return;
83425
83530
  }
@@ -84653,7 +84758,7 @@ var ts;
84653
84758
  return errorType;
84654
84759
  }
84655
84760
  if (ts.isBindingPattern(node)) {
84656
- return getTypeForVariableLikeDeclaration(node.parent, /*includeOptionality*/ true) || errorType;
84761
+ return getTypeForVariableLikeDeclaration(node.parent, /*includeOptionality*/ true, 0 /* Normal */) || errorType;
84657
84762
  }
84658
84763
  if (isInRightSideOfImportOrExportAssignment(node)) {
84659
84764
  var symbol = getSymbolAtLocation(node);
@@ -114400,9 +114505,9 @@ var ts;
114400
114505
  ts.Diagnostics.A_return_statement_cannot_be_used_inside_a_class_static_block.code,
114401
114506
  ts.Diagnostics.A_set_accessor_cannot_have_rest_parameter.code,
114402
114507
  ts.Diagnostics.A_set_accessor_must_have_exactly_one_parameter.code,
114403
- ts.Diagnostics.An_export_declaration_can_only_be_used_in_a_module.code,
114508
+ ts.Diagnostics.An_export_declaration_can_only_be_used_at_the_top_level_of_a_module.code,
114404
114509
  ts.Diagnostics.An_export_declaration_cannot_have_modifiers.code,
114405
- ts.Diagnostics.An_import_declaration_can_only_be_used_in_a_namespace_or_module.code,
114510
+ ts.Diagnostics.An_import_declaration_can_only_be_used_at_the_top_level_of_a_module.code,
114406
114511
  ts.Diagnostics.An_import_declaration_cannot_have_modifiers.code,
114407
114512
  ts.Diagnostics.An_object_member_cannot_be_declared_optional.code,
114408
114513
  ts.Diagnostics.Argument_of_dynamic_import_cannot_be_spread_element.code,
@@ -115470,7 +115575,7 @@ var ts;
115470
115575
  ts.Debug.assert(!!sourceFile.bindDiagnostics);
115471
115576
  var isJs = sourceFile.scriptKind === 1 /* JS */ || sourceFile.scriptKind === 2 /* JSX */;
115472
115577
  var isCheckJs = isJs && ts.isCheckJsEnabledForFile(sourceFile, options);
115473
- var isPlainJs = isJs && !sourceFile.checkJsDirective && options.checkJs === undefined;
115578
+ var isPlainJs = ts.isPlainJsFile(sourceFile, options.checkJs);
115474
115579
  var isTsNoCheck = !!sourceFile.checkJsDirective && sourceFile.checkJsDirective.enabled === false;
115475
115580
  // By default, only type-check .ts, .tsx, Deferred, plain JS, checked JS and External
115476
115581
  // - plain JS: .js files with no // ts-check and checkJs: undefined