typescript 4.6.0-dev.20220206 → 4.6.0-dev.20220210

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/typescript.js CHANGED
@@ -294,7 +294,7 @@ var ts;
294
294
  // The following is baselined as a literal template type without intervention
295
295
  /** The version of the TypeScript compiler release */
296
296
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
297
- ts.version = ts.versionMajorMinor + ".0-dev.20220206";
297
+ ts.version = ts.versionMajorMinor + ".0-dev.20220210";
298
298
  /* @internal */
299
299
  var Comparison;
300
300
  (function (Comparison) {
@@ -8239,10 +8239,10 @@ var ts;
8239
8239
  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."),
8240
8240
  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."),
8241
8241
  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."),
8242
- 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."),
8243
- 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."),
8242
+ 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."),
8243
+ 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."),
8244
8244
  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."),
8245
- 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."),
8245
+ 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."),
8246
8246
  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'."),
8247
8247
  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'."),
8248
8248
  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."),
@@ -8410,6 +8410,8 @@ var ts;
8410
8410
  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."),
8411
8411
  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."),
8412
8412
  catch_or_finally_expected: diag(1472, ts.DiagnosticCategory.Error, "catch_or_finally_expected_1472", "'catch' or 'finally' expected."),
8413
+ 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."),
8414
+ 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."),
8413
8415
  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."),
8414
8416
  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."),
8415
8417
  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),
@@ -14091,6 +14093,10 @@ var ts;
14091
14093
  return undefined;
14092
14094
  }
14093
14095
  ts.getDeclarationOfKind = getDeclarationOfKind;
14096
+ function getDeclarationsOfKind(symbol, kind) {
14097
+ return ts.filter(symbol.declarations || ts.emptyArray, function (d) { return d.kind === kind; });
14098
+ }
14099
+ ts.getDeclarationsOfKind = getDeclarationsOfKind;
14094
14100
  function createSymbolTable(symbols) {
14095
14101
  var result = new ts.Map();
14096
14102
  if (symbols) {
@@ -14326,6 +14332,10 @@ var ts;
14326
14332
  return getSourceFileOfNode(module.valueDeclaration || getNonAugmentationDeclaration(module));
14327
14333
  }
14328
14334
  ts.getSourceFileOfModule = getSourceFileOfModule;
14335
+ function isPlainJsFile(file, checkJs) {
14336
+ return !!file && (file.scriptKind === 1 /* JS */ || file.scriptKind === 2 /* JSX */) && !file.checkJsDirective && checkJs === undefined;
14337
+ }
14338
+ ts.isPlainJsFile = isPlainJsFile;
14329
14339
  function isStatementWithLocals(node) {
14330
14340
  switch (node.kind) {
14331
14341
  case 234 /* Block */:
@@ -47103,6 +47113,9 @@ var ts;
47103
47113
  CheckMode[CheckMode["SkipContextSensitive"] = 4] = "SkipContextSensitive";
47104
47114
  CheckMode[CheckMode["SkipGenericFunctions"] = 8] = "SkipGenericFunctions";
47105
47115
  CheckMode[CheckMode["IsForSignatureHelp"] = 16] = "IsForSignatureHelp";
47116
+ CheckMode[CheckMode["RestBindingElement"] = 32] = "RestBindingElement";
47117
+ // e.g. in `const { a, ...rest } = foo`, when checking the type of `foo` to determine the type of `rest`,
47118
+ // we need to preserve generic types instead of substituting them for constraints
47106
47119
  })(CheckMode || (CheckMode = {}));
47107
47120
  var SignatureCheckMode;
47108
47121
  (function (SignatureCheckMode) {
@@ -48155,13 +48168,13 @@ var ts;
48155
48168
  else { // error
48156
48169
  var isEitherEnum = !!(target.flags & 384 /* Enum */ || source.flags & 384 /* Enum */);
48157
48170
  var isEitherBlockScoped_1 = !!(target.flags & 2 /* BlockScopedVariable */ || source.flags & 2 /* BlockScopedVariable */);
48158
- var message = isEitherEnum
48159
- ? ts.Diagnostics.Enum_declarations_can_only_merge_with_namespace_or_other_enum_declarations
48160
- : isEitherBlockScoped_1
48161
- ? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0
48171
+ var message = isEitherEnum ? ts.Diagnostics.Enum_declarations_can_only_merge_with_namespace_or_other_enum_declarations
48172
+ : isEitherBlockScoped_1 ? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0
48162
48173
  : ts.Diagnostics.Duplicate_identifier_0;
48163
48174
  var sourceSymbolFile = source.declarations && ts.getSourceFileOfNode(source.declarations[0]);
48164
48175
  var targetSymbolFile = target.declarations && ts.getSourceFileOfNode(target.declarations[0]);
48176
+ var isSourcePlainJs = ts.isPlainJsFile(sourceSymbolFile, compilerOptions.checkJs);
48177
+ var isTargetPlainJs = ts.isPlainJsFile(targetSymbolFile, compilerOptions.checkJs);
48165
48178
  var symbolName_1 = symbolToString(source);
48166
48179
  // Collect top-level duplicate identifier errors into one mapping, so we can then merge their diagnostics if there are a bunch
48167
48180
  if (sourceSymbolFile && targetSymbolFile && amalgamatedDuplicates && !isEitherEnum && sourceSymbolFile !== targetSymbolFile) {
@@ -48173,12 +48186,16 @@ var ts;
48173
48186
  var conflictingSymbolInfo = ts.getOrUpdate(filesDuplicates.conflictingSymbols, symbolName_1, function () {
48174
48187
  return ({ isBlockScoped: isEitherBlockScoped_1, firstFileLocations: [], secondFileLocations: [] });
48175
48188
  });
48176
- addDuplicateLocations(conflictingSymbolInfo.firstFileLocations, source);
48177
- addDuplicateLocations(conflictingSymbolInfo.secondFileLocations, target);
48189
+ if (!isSourcePlainJs)
48190
+ addDuplicateLocations(conflictingSymbolInfo.firstFileLocations, source);
48191
+ if (!isTargetPlainJs)
48192
+ addDuplicateLocations(conflictingSymbolInfo.secondFileLocations, target);
48178
48193
  }
48179
48194
  else {
48180
- addDuplicateDeclarationErrorsForSymbols(source, message, symbolName_1, target);
48181
- addDuplicateDeclarationErrorsForSymbols(target, message, symbolName_1, source);
48195
+ if (!isSourcePlainJs)
48196
+ addDuplicateDeclarationErrorsForSymbols(source, message, symbolName_1, target);
48197
+ if (!isTargetPlainJs)
48198
+ addDuplicateDeclarationErrorsForSymbols(target, message, symbolName_1, source);
48182
48199
  }
48183
48200
  }
48184
48201
  return target;
@@ -48635,6 +48652,8 @@ var ts;
48635
48652
  // type parameters are visible in parameter list, return type and type parameter list
48636
48653
  ? lastLocation === location.type ||
48637
48654
  lastLocation.kind === 163 /* Parameter */ ||
48655
+ lastLocation.kind === 338 /* JSDocParameterTag */ ||
48656
+ lastLocation.kind === 339 /* JSDocReturnTag */ ||
48638
48657
  lastLocation.kind === 162 /* TypeParameter */
48639
48658
  // local types not visible outside the function body
48640
48659
  : false;
@@ -48894,9 +48913,9 @@ var ts;
48894
48913
  lastSelfReferenceLocation = location;
48895
48914
  }
48896
48915
  lastLocation = location;
48897
- location = ts.isJSDocTemplateTag(location) ?
48898
- ts.getEffectiveContainerForJSDocTemplateTag(location) || location.parent :
48899
- location.parent;
48916
+ location = ts.isJSDocTemplateTag(location) ? ts.getEffectiveContainerForJSDocTemplateTag(location) || location.parent :
48917
+ ts.isJSDocParameterTag(location) || ts.isJSDocReturnTag(location) ? ts.getHostSignatureFromJSDoc(location) || location.parent :
48918
+ location.parent;
48900
48919
  }
48901
48920
  // We just climbed up parents looking for the name, meaning that we started in a descendant node of `lastLocation`.
48902
48921
  // If `result === lastSelfReferenceLocation.symbol`, that means that we are somewhere inside `lastSelfReferenceLocation` looking up a name, and resolving to `lastLocation` itself.
@@ -50030,16 +50049,20 @@ var ts;
50030
50049
  return;
50031
50050
  }
50032
50051
  var host = ts.getJSDocHost(node);
50033
- if (host &&
50034
- ts.isExpressionStatement(host) &&
50035
- ts.isBinaryExpression(host.expression) &&
50036
- ts.getAssignmentDeclarationKind(host.expression) === 3 /* PrototypeProperty */) {
50037
- // X.prototype.m = /** @param {K} p */ function () { } <-- look for K on X's declaration
50052
+ if (host && ts.isExpressionStatement(host) && ts.isPrototypePropertyAssignment(host.expression)) {
50053
+ // /** @param {K} p */ X.prototype.m = function () { } <-- look for K on X's declaration
50038
50054
  var symbol = getSymbolOfNode(host.expression.left);
50039
50055
  if (symbol) {
50040
50056
  return getDeclarationOfJSPrototypeContainer(symbol);
50041
50057
  }
50042
50058
  }
50059
+ if (host && ts.isFunctionExpression(host) && ts.isPrototypePropertyAssignment(host.parent) && ts.isExpressionStatement(host.parent.parent)) {
50060
+ // X.prototype.m = /** @param {K} p */ function () { } <-- look for K on X's declaration
50061
+ var symbol = getSymbolOfNode(host.parent.left);
50062
+ if (symbol) {
50063
+ return getDeclarationOfJSPrototypeContainer(symbol);
50064
+ }
50065
+ }
50043
50066
  if (host && (ts.isObjectLiteralMethod(host) || ts.isPropertyAssignment(host)) &&
50044
50067
  ts.isBinaryExpression(host.parent.parent) &&
50045
50068
  ts.getAssignmentDeclarationKind(host.parent.parent) === 6 /* Prototype */) {
@@ -54526,9 +54549,12 @@ var ts;
54526
54549
  }
54527
54550
  // Return the type of a binding element parent. We check SymbolLinks first to see if a type has been
54528
54551
  // assigned by contextual typing.
54529
- function getTypeForBindingElementParent(node) {
54552
+ function getTypeForBindingElementParent(node, checkMode) {
54553
+ if (checkMode !== 0 /* Normal */) {
54554
+ return getTypeForVariableLikeDeclaration(node, /*includeOptionality*/ false, checkMode);
54555
+ }
54530
54556
  var symbol = getSymbolOfNode(node);
54531
- return symbol && getSymbolLinks(symbol).type || getTypeForVariableLikeDeclaration(node, /*includeOptionality*/ false);
54557
+ return symbol && getSymbolLinks(symbol).type || getTypeForVariableLikeDeclaration(node, /*includeOptionality*/ false, checkMode);
54532
54558
  }
54533
54559
  function getRestType(source, properties, symbol) {
54534
54560
  source = filterType(source, function (t) { return !(t.flags & 98304 /* Nullable */); });
@@ -54646,7 +54672,8 @@ var ts;
54646
54672
  }
54647
54673
  /** Return the inferred type for a binding element */
54648
54674
  function getTypeForBindingElement(declaration) {
54649
- var parentType = getTypeForBindingElementParent(declaration.parent.parent);
54675
+ var checkMode = declaration.dotDotDotToken ? 32 /* RestBindingElement */ : 0 /* Normal */;
54676
+ var parentType = getTypeForBindingElementParent(declaration.parent.parent, checkMode);
54650
54677
  return parentType && getBindingElementTypeFromParentType(declaration, parentType);
54651
54678
  }
54652
54679
  function getBindingElementTypeFromParentType(declaration, parentType) {
@@ -54718,9 +54745,9 @@ var ts;
54718
54745
  if (ts.getEffectiveTypeAnnotationNode(ts.walkUpBindingElementsAndPatterns(declaration))) {
54719
54746
  // In strict null checking mode, if a default value of a non-undefined type is specified, remove
54720
54747
  // undefined from the final type.
54721
- return strictNullChecks && !(getFalsyFlags(checkDeclarationInitializer(declaration)) & 32768 /* Undefined */) ? getNonUndefinedType(type) : type;
54748
+ return strictNullChecks && !(getFalsyFlags(checkDeclarationInitializer(declaration, 0 /* Normal */)) & 32768 /* Undefined */) ? getNonUndefinedType(type) : type;
54722
54749
  }
54723
- return widenTypeInferredFromInitializer(declaration, getUnionType([getNonUndefinedType(type), checkDeclarationInitializer(declaration)], 2 /* Subtype */));
54750
+ return widenTypeInferredFromInitializer(declaration, getUnionType([getNonUndefinedType(type), checkDeclarationInitializer(declaration, 0 /* Normal */)], 2 /* Subtype */));
54724
54751
  }
54725
54752
  function getTypeForDeclarationFromJSDocComment(declaration) {
54726
54753
  var jsdocType = ts.getJSDocType(declaration);
@@ -54743,11 +54770,11 @@ var ts;
54743
54770
  return strictNullChecks && isOptional ? getOptionalType(type, isProperty) : type;
54744
54771
  }
54745
54772
  // Return the inferred type for a variable, parameter, or property declaration
54746
- function getTypeForVariableLikeDeclaration(declaration, includeOptionality) {
54773
+ function getTypeForVariableLikeDeclaration(declaration, includeOptionality, checkMode) {
54747
54774
  // A variable declared in a for..in statement is of type string, or of type keyof T when the
54748
54775
  // right hand expression is of a type parameter type.
54749
54776
  if (ts.isVariableDeclaration(declaration) && declaration.parent.parent.kind === 242 /* ForInStatement */) {
54750
- var indexType = getIndexType(getNonNullableTypeIfNeeded(checkExpression(declaration.parent.parent.expression)));
54777
+ var indexType = getIndexType(getNonNullableTypeIfNeeded(checkExpression(declaration.parent.parent.expression, /*checkMode*/ checkMode)));
54751
54778
  return indexType.flags & (262144 /* TypeParameter */ | 4194304 /* Index */) ? getExtractStringType(indexType) : stringType;
54752
54779
  }
54753
54780
  if (ts.isVariableDeclaration(declaration) && declaration.parent.parent.kind === 243 /* ForOfStatement */) {
@@ -54824,7 +54851,7 @@ var ts;
54824
54851
  return containerObjectType;
54825
54852
  }
54826
54853
  }
54827
- var type = widenTypeInferredFromInitializer(declaration, checkDeclarationInitializer(declaration));
54854
+ var type = widenTypeInferredFromInitializer(declaration, checkDeclarationInitializer(declaration, checkMode));
54828
54855
  return addOptionality(type, isProperty, isOptional);
54829
54856
  }
54830
54857
  if (ts.isPropertyDeclaration(declaration) && (noImplicitAny || ts.isInJSFile(declaration))) {
@@ -55196,7 +55223,7 @@ var ts;
55196
55223
  // contextual type or, if the element itself is a binding pattern, with the type implied by that binding
55197
55224
  // pattern.
55198
55225
  var contextualType = ts.isBindingPattern(element.name) ? getTypeFromBindingPattern(element.name, /*includePatternInType*/ true, /*reportErrors*/ false) : unknownType;
55199
- return addOptionality(widenTypeInferredFromInitializer(element, checkDeclarationInitializer(element, contextualType)));
55226
+ return addOptionality(widenTypeInferredFromInitializer(element, checkDeclarationInitializer(element, 0 /* Normal */, contextualType)));
55200
55227
  }
55201
55228
  if (ts.isBindingPattern(element.name)) {
55202
55229
  return getTypeFromBindingPattern(element.name, includePatternInType, reportErrors);
@@ -55285,7 +55312,7 @@ var ts;
55285
55312
  // binding pattern [x, s = ""]. Because the contextual type is a tuple type, the resulting type of [1, "one"] is the
55286
55313
  // tuple type [number, string]. Thus, the type inferred for 'x' is number and the type inferred for 's' is string.
55287
55314
  function getWidenedTypeForVariableLikeDeclaration(declaration, reportErrors) {
55288
- return widenTypeForVariableLikeDeclaration(getTypeForVariableLikeDeclaration(declaration, /*includeOptionality*/ true), declaration, reportErrors);
55315
+ return widenTypeForVariableLikeDeclaration(getTypeForVariableLikeDeclaration(declaration, /*includeOptionality*/ true, 0 /* Normal */), declaration, reportErrors);
55289
55316
  }
55290
55317
  function isGlobalSymbolConstructor(node) {
55291
55318
  var symbol = getSymbolOfNode(node);
@@ -55514,10 +55541,12 @@ var ts;
55514
55541
  if (writing === void 0) { writing = false; }
55515
55542
  var getter = ts.getDeclarationOfKind(symbol, 171 /* GetAccessor */);
55516
55543
  var setter = ts.getDeclarationOfKind(symbol, 172 /* SetAccessor */);
55517
- var setterType = getAnnotatedAccessorType(setter);
55518
55544
  // For write operations, prioritize type annotations on the setter
55519
- if (writing && setterType) {
55520
- return instantiateTypeIfNeeded(setterType, symbol);
55545
+ if (writing) {
55546
+ var setterType_1 = getAnnotatedAccessorType(setter);
55547
+ if (setterType_1) {
55548
+ return instantiateTypeIfNeeded(setterType_1, symbol);
55549
+ }
55521
55550
  }
55522
55551
  // Else defer to the getter type
55523
55552
  if (getter && ts.isInJSFile(getter)) {
@@ -55532,6 +55561,7 @@ var ts;
55532
55561
  return instantiateTypeIfNeeded(getterType, symbol);
55533
55562
  }
55534
55563
  // If the user didn't specify a return type, try to use the set-accessor's parameter type.
55564
+ var setterType = getAnnotatedAccessorType(setter);
55535
55565
  if (setterType) {
55536
55566
  return setterType;
55537
55567
  }
@@ -55680,6 +55710,39 @@ var ts;
55680
55710
  }
55681
55711
  return links.type;
55682
55712
  }
55713
+ function getWriteTypeOfSymbolWithDeferredType(symbol) {
55714
+ var links = getSymbolLinks(symbol);
55715
+ if (!links.writeType && links.deferralWriteConstituents) {
55716
+ ts.Debug.assertIsDefined(links.deferralParent);
55717
+ ts.Debug.assertIsDefined(links.deferralConstituents);
55718
+ links.writeType = links.deferralParent.flags & 1048576 /* Union */ ? getUnionType(links.deferralWriteConstituents) : getIntersectionType(links.deferralWriteConstituents);
55719
+ }
55720
+ return links.writeType;
55721
+ }
55722
+ /**
55723
+ * Distinct write types come only from set accessors, but union and intersection
55724
+ * properties deriving from set accessors will either pre-compute or defer the
55725
+ * union or intersection of the writeTypes of their constituents. To account for
55726
+ * this, we will assume that any deferred type or transient symbol may have a
55727
+ * `writeType` (or a deferred write type ready to be computed) that should be
55728
+ * used before looking for set accessor declarations.
55729
+ */
55730
+ function getWriteTypeOfSymbol(symbol) {
55731
+ var checkFlags = ts.getCheckFlags(symbol);
55732
+ if (checkFlags & 65536 /* DeferredType */) {
55733
+ var writeType = getWriteTypeOfSymbolWithDeferredType(symbol);
55734
+ if (writeType) {
55735
+ return writeType;
55736
+ }
55737
+ }
55738
+ if (symbol.flags & 33554432 /* Transient */) {
55739
+ var writeType = symbol.writeType;
55740
+ if (writeType) {
55741
+ return writeType;
55742
+ }
55743
+ }
55744
+ return getSetAccessorTypeOfSymbol(symbol);
55745
+ }
55683
55746
  function getSetAccessorTypeOfSymbol(symbol) {
55684
55747
  if (symbol.flags & 98304 /* Accessor */) {
55685
55748
  var type = getTypeOfSetAccessor(symbol);
@@ -58050,6 +58113,7 @@ var ts;
58050
58113
  var firstType;
58051
58114
  var nameType;
58052
58115
  var propTypes = [];
58116
+ var writeTypes;
58053
58117
  var firstValueDeclaration;
58054
58118
  var hasNonUniformValueDeclaration = false;
58055
58119
  for (var _d = 0, props_1 = props; _d < props_1.length; _d++) {
@@ -58066,6 +58130,10 @@ var ts;
58066
58130
  firstType = type;
58067
58131
  nameType = getSymbolLinks(prop).nameType;
58068
58132
  }
58133
+ var writeType = getWriteTypeOfSymbol(prop);
58134
+ if (writeTypes || writeType !== type) {
58135
+ writeTypes = ts.append(!writeTypes ? propTypes.slice() : writeTypes, writeType);
58136
+ }
58069
58137
  else if (type !== firstType) {
58070
58138
  checkFlags |= 64 /* HasNonUniformType */;
58071
58139
  }
@@ -58094,9 +58162,13 @@ var ts;
58094
58162
  result.checkFlags |= 65536 /* DeferredType */;
58095
58163
  result.deferralParent = containingType;
58096
58164
  result.deferralConstituents = propTypes;
58165
+ result.deferralWriteConstituents = writeTypes;
58097
58166
  }
58098
58167
  else {
58099
58168
  result.type = isUnion ? getUnionType(propTypes) : getIntersectionType(propTypes);
58169
+ if (writeTypes) {
58170
+ result.writeType = isUnion ? getUnionType(writeTypes) : getIntersectionType(writeTypes);
58171
+ }
58100
58172
  }
58101
58173
  return result;
58102
58174
  }
@@ -59238,7 +59310,7 @@ var ts;
59238
59310
  }
59239
59311
  function getImpliedConstraint(type, checkNode, extendsNode) {
59240
59312
  return isUnaryTupleTypeNode(checkNode) && isUnaryTupleTypeNode(extendsNode) ? getImpliedConstraint(type, checkNode.elements[0], extendsNode.elements[0]) :
59241
- getActualTypeVariable(getTypeFromTypeNode(checkNode)) === type ? getTypeFromTypeNode(extendsNode) :
59313
+ getActualTypeVariable(getTypeFromTypeNode(checkNode)) === getActualTypeVariable(type) ? getTypeFromTypeNode(extendsNode) :
59242
59314
  undefined;
59243
59315
  }
59244
59316
  function getConditionalFlowTypeOfType(type, node) {
@@ -70047,12 +70119,16 @@ var ts;
70047
70119
  function isGenericTypeWithoutNullableConstraint(type) {
70048
70120
  return !!(type.flags & 465829888 /* Instantiable */ && !maybeTypeOfKind(getBaseConstraintOrType(type), 98304 /* Nullable */));
70049
70121
  }
70050
- function hasNonBindingPatternContextualTypeWithNoGenericTypes(node) {
70122
+ function hasContextualTypeWithNoGenericTypes(node, checkMode) {
70051
70123
  // Computing the contextual type for a child of a JSX element involves resolving the type of the
70052
70124
  // element's tag name, so we exclude that here to avoid circularities.
70125
+ // If check mode has `CheckMode.RestBindingElement`, we skip binding pattern contextual types,
70126
+ // as we want the type of a rest element to be generic when possible.
70053
70127
  var contextualType = (ts.isIdentifier(node) || ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node)) &&
70054
70128
  !((ts.isJsxOpeningElement(node.parent) || ts.isJsxSelfClosingElement(node.parent)) && node.parent.tagName === node) &&
70055
- getContextualType(node, 8 /* SkipBindingPatterns */);
70129
+ (checkMode && checkMode & 32 /* RestBindingElement */ ?
70130
+ getContextualType(node, 8 /* SkipBindingPatterns */)
70131
+ : getContextualType(node));
70056
70132
  return contextualType && !isGenericType(contextualType);
70057
70133
  }
70058
70134
  function getNarrowableTypeForReference(type, reference, checkMode) {
@@ -70065,7 +70141,7 @@ var ts;
70065
70141
  // 'string | undefined' to give control flow analysis the opportunity to narrow to type 'string'.
70066
70142
  var substituteConstraints = !(checkMode && checkMode & 2 /* Inferential */) &&
70067
70143
  someType(type, isGenericTypeWithUnionConstraint) &&
70068
- (isConstraintPosition(type, reference) || hasNonBindingPatternContextualTypeWithNoGenericTypes(reference));
70144
+ (isConstraintPosition(type, reference) || hasContextualTypeWithNoGenericTypes(reference, checkMode));
70069
70145
  return substituteConstraints ? mapType(type, function (t) { return t.flags & 465829888 /* Instantiable */ && !isMappedTypeGenericIndexedAccess(t) ? getBaseConstraintOrType(t) : t; }) : type;
70070
70146
  }
70071
70147
  function isExportOrExportExpression(location) {
@@ -70133,7 +70209,7 @@ var ts;
70133
70209
  var links = getNodeLinks(location);
70134
70210
  if (!(links.flags & 268435456 /* InCheckIdentifier */)) {
70135
70211
  links.flags |= 268435456 /* InCheckIdentifier */;
70136
- var parentType = getTypeForBindingElementParent(parent);
70212
+ var parentType = getTypeForBindingElementParent(parent, 0 /* Normal */);
70137
70213
  links.flags &= ~268435456 /* InCheckIdentifier */;
70138
70214
  if (parentType && parentType.flags & 1048576 /* Union */ && !(parent.kind === 163 /* Parameter */ && isSymbolAssigned(symbol))) {
70139
70215
  var pattern = declaration.parent;
@@ -70986,7 +71062,7 @@ var ts;
70986
71062
  var parent = declaration.parent.parent;
70987
71063
  var name = declaration.propertyName || declaration.name;
70988
71064
  var parentType = getContextualTypeForVariableLikeDeclaration(parent) ||
70989
- parent.kind !== 202 /* BindingElement */ && parent.initializer && checkDeclarationInitializer(parent);
71065
+ parent.kind !== 202 /* BindingElement */ && parent.initializer && checkDeclarationInitializer(parent, declaration.dotDotDotToken ? 32 /* RestBindingElement */ : 0 /* Normal */);
70990
71066
  if (!parentType || ts.isBindingPattern(name) || ts.isComputedNonLiteralName(name))
70991
71067
  return undefined;
70992
71068
  if (parent.name.kind === 201 /* ArrayBindingPattern */) {
@@ -73227,7 +73303,7 @@ var ts;
73227
73303
  error(right, ts.Diagnostics.Cannot_assign_to_0_because_it_is_a_read_only_property, ts.idText(right));
73228
73304
  return errorType;
73229
73305
  }
73230
- propType = isThisPropertyAccessInConstructor(node, prop) ? autoType : writing ? getSetAccessorTypeOfSymbol(prop) : getTypeOfSymbol(prop);
73306
+ propType = isThisPropertyAccessInConstructor(node, prop) ? autoType : writing ? getWriteTypeOfSymbol(prop) : getTypeOfSymbol(prop);
73231
73307
  }
73232
73308
  return getFlowTypeOfAccessExpression(node, prop, propType, right, checkMode);
73233
73309
  }
@@ -76152,7 +76228,7 @@ var ts;
76152
76228
  var links = getSymbolLinks(parameter);
76153
76229
  if (!links.type) {
76154
76230
  var declaration = parameter.valueDeclaration;
76155
- links.type = type || getWidenedTypeForVariableLikeDeclaration(declaration, /*includeOptionality*/ true);
76231
+ links.type = type || getWidenedTypeForVariableLikeDeclaration(declaration, /*reportErrors*/ true);
76156
76232
  if (declaration.name.kind !== 79 /* Identifier */) {
76157
76233
  // if inference didn't come up with anything but unknown, fall back to the binding pattern if present.
76158
76234
  if (links.type === unknownType) {
@@ -77883,11 +77959,11 @@ var ts;
77883
77959
  }
77884
77960
  }
77885
77961
  function checkExpressionCached(node, checkMode) {
77962
+ if (checkMode && checkMode !== 0 /* Normal */) {
77963
+ return checkExpression(node, checkMode);
77964
+ }
77886
77965
  var links = getNodeLinks(node);
77887
77966
  if (!links.resolvedType) {
77888
- if (checkMode && checkMode !== 0 /* Normal */) {
77889
- return checkExpression(node, checkMode);
77890
- }
77891
77967
  // When computing a type that we're going to cache, we need to ignore any ongoing control flow
77892
77968
  // analysis because variables may have transient types in indeterminable states. Moving flowLoopStart
77893
77969
  // to the top of the stack ensures all transient types are computed from a known point.
@@ -77907,10 +77983,12 @@ var ts;
77907
77983
  node.kind === 228 /* AsExpression */ ||
77908
77984
  ts.isJSDocTypeAssertion(node);
77909
77985
  }
77910
- function checkDeclarationInitializer(declaration, contextualType) {
77986
+ function checkDeclarationInitializer(declaration, checkMode, contextualType) {
77911
77987
  var initializer = ts.getEffectiveInitializer(declaration);
77912
77988
  var type = getQuickTypeOfExpression(initializer) ||
77913
- (contextualType ? checkExpressionWithContextualType(initializer, contextualType, /*inferenceContext*/ undefined, 0 /* Normal */) : checkExpressionCached(initializer));
77989
+ (contextualType ?
77990
+ checkExpressionWithContextualType(initializer, contextualType, /*inferenceContext*/ undefined, checkMode || 0 /* Normal */)
77991
+ : checkExpressionCached(initializer, checkMode));
77914
77992
  return ts.isParameter(declaration) && declaration.name.kind === 201 /* ArrayBindingPattern */ &&
77915
77993
  isTupleType(type) && !type.target.hasRestElement && getTypeReferenceArity(type) < declaration.name.elements.length ?
77916
77994
  padTupleType(type, declaration.name) : type;
@@ -80847,7 +80925,8 @@ var ts;
80847
80925
  }
80848
80926
  // check private/protected variable access
80849
80927
  var parent = node.parent.parent;
80850
- var parentType = getTypeForBindingElementParent(parent);
80928
+ var parentCheckMode = node.dotDotDotToken ? 32 /* RestBindingElement */ : 0 /* Normal */;
80929
+ var parentType = getTypeForBindingElementParent(parent, parentCheckMode);
80851
80930
  var name = node.propertyName || node.name;
80852
80931
  if (parentType && !ts.isBindingPattern(name)) {
80853
80932
  var exprType = getLiteralTypeFromPropertyName(name);
@@ -82086,7 +82165,7 @@ var ts;
82086
82165
  var declaration = catchClause.variableDeclaration;
82087
82166
  var typeNode = ts.getEffectiveTypeAnnotationNode(ts.getRootDeclaration(declaration));
82088
82167
  if (typeNode) {
82089
- var type = getTypeForVariableLikeDeclaration(declaration, /*includeOptionality*/ false);
82168
+ var type = getTypeForVariableLikeDeclaration(declaration, /*includeOptionality*/ false, 0 /* Normal */);
82090
82169
  if (type && !(type.flags & 3 /* AnyOrUnknown */)) {
82091
82170
  grammarErrorOnFirstToken(typeNode, ts.Diagnostics.Catch_clause_variable_type_annotation_must_be_any_or_unknown_if_specified);
82092
82171
  }
@@ -83192,7 +83271,7 @@ var ts;
83192
83271
  var isAmbientExternalModule = ts.isAmbientModule(node);
83193
83272
  var contextErrorMessage = isAmbientExternalModule
83194
83273
  ? ts.Diagnostics.An_ambient_module_declaration_is_only_allowed_at_the_top_level_in_a_file
83195
- : ts.Diagnostics.A_namespace_declaration_is_only_allowed_in_a_namespace_or_module;
83274
+ : ts.Diagnostics.A_namespace_declaration_is_only_allowed_at_the_top_level_of_a_namespace_or_module;
83196
83275
  if (checkGrammarModuleElementContext(node, contextErrorMessage)) {
83197
83276
  // If we hit a module declaration in an illegal context, just bail out to avoid cascading errors.
83198
83277
  return;
@@ -83508,7 +83587,7 @@ var ts;
83508
83587
  }
83509
83588
  }
83510
83589
  function checkImportDeclaration(node) {
83511
- if (checkGrammarModuleElementContext(node, ts.Diagnostics.An_import_declaration_can_only_be_used_in_a_namespace_or_module)) {
83590
+ 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)) {
83512
83591
  // If we hit an import declaration in an illegal context, just bail out to avoid cascading errors.
83513
83592
  return;
83514
83593
  }
@@ -83541,7 +83620,7 @@ var ts;
83541
83620
  checkAssertClause(node);
83542
83621
  }
83543
83622
  function checkImportEqualsDeclaration(node) {
83544
- if (checkGrammarModuleElementContext(node, ts.Diagnostics.An_import_declaration_can_only_be_used_in_a_namespace_or_module)) {
83623
+ 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)) {
83545
83624
  // If we hit an import declaration in an illegal context, just bail out to avoid cascading errors.
83546
83625
  return;
83547
83626
  }
@@ -83578,7 +83657,7 @@ var ts;
83578
83657
  }
83579
83658
  }
83580
83659
  function checkExportDeclaration(node) {
83581
- if (checkGrammarModuleElementContext(node, ts.Diagnostics.An_export_declaration_can_only_be_used_in_a_module)) {
83660
+ 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)) {
83582
83661
  // If we hit an export in an illegal context, just bail out to avoid cascading errors.
83583
83662
  return;
83584
83663
  }
@@ -84812,7 +84891,7 @@ var ts;
84812
84891
  return errorType;
84813
84892
  }
84814
84893
  if (ts.isBindingPattern(node)) {
84815
- return getTypeForVariableLikeDeclaration(node.parent, /*includeOptionality*/ true) || errorType;
84894
+ return getTypeForVariableLikeDeclaration(node.parent, /*includeOptionality*/ true, 0 /* Normal */) || errorType;
84816
84895
  }
84817
84896
  if (isInRightSideOfImportOrExportAssignment(node)) {
84818
84897
  var symbol = getSymbolAtLocation(node);
@@ -114559,9 +114638,9 @@ var ts;
114559
114638
  ts.Diagnostics.A_return_statement_cannot_be_used_inside_a_class_static_block.code,
114560
114639
  ts.Diagnostics.A_set_accessor_cannot_have_rest_parameter.code,
114561
114640
  ts.Diagnostics.A_set_accessor_must_have_exactly_one_parameter.code,
114562
- ts.Diagnostics.An_export_declaration_can_only_be_used_in_a_module.code,
114641
+ ts.Diagnostics.An_export_declaration_can_only_be_used_at_the_top_level_of_a_module.code,
114563
114642
  ts.Diagnostics.An_export_declaration_cannot_have_modifiers.code,
114564
- ts.Diagnostics.An_import_declaration_can_only_be_used_in_a_namespace_or_module.code,
114643
+ ts.Diagnostics.An_import_declaration_can_only_be_used_at_the_top_level_of_a_module.code,
114565
114644
  ts.Diagnostics.An_import_declaration_cannot_have_modifiers.code,
114566
114645
  ts.Diagnostics.An_object_member_cannot_be_declared_optional.code,
114567
114646
  ts.Diagnostics.Argument_of_dynamic_import_cannot_be_spread_element.code,
@@ -115629,7 +115708,7 @@ var ts;
115629
115708
  ts.Debug.assert(!!sourceFile.bindDiagnostics);
115630
115709
  var isJs = sourceFile.scriptKind === 1 /* JS */ || sourceFile.scriptKind === 2 /* JSX */;
115631
115710
  var isCheckJs = isJs && ts.isCheckJsEnabledForFile(sourceFile, options);
115632
- var isPlainJs = isJs && !sourceFile.checkJsDirective && options.checkJs === undefined;
115711
+ var isPlainJs = ts.isPlainJsFile(sourceFile, options.checkJs);
115633
115712
  var isTsNoCheck = !!sourceFile.checkJsDirective && sourceFile.checkJsDirective.enabled === false;
115634
115713
  // By default, only type-check .ts, .tsx, Deferred, plain JS, checked JS and External
115635
115714
  // - plain JS: .js files with no // ts-check and checkJs: undefined
@@ -130939,7 +131018,8 @@ var ts;
130939
131018
  case 103 /* NewKeyword */:
130940
131019
  return checker.getContextualType(parent);
130941
131020
  case 82 /* CaseKeyword */:
130942
- return ts.getSwitchedType(ts.cast(parent, ts.isCaseClause), checker);
131021
+ var caseClause = ts.tryCast(parent, ts.isCaseClause);
131022
+ return caseClause ? ts.getSwitchedType(caseClause, checker) : undefined;
130943
131023
  case 18 /* OpenBraceToken */:
130944
131024
  return ts.isJsxExpression(parent) && !ts.isJsxElement(parent.parent) && !ts.isJsxFragment(parent.parent) ? checker.getContextualTypeForJsxAttribute(parent.parent) : undefined;
130945
131025
  default:
@@ -133584,7 +133664,24 @@ var ts;
133584
133664
  function acquireOrUpdateDocument(fileName, path, compilationSettings, key, scriptSnapshot, version, acquiring, scriptKind) {
133585
133665
  scriptKind = ts.ensureScriptKind(fileName, scriptKind);
133586
133666
  var scriptTarget = scriptKind === 6 /* JSON */ ? 100 /* JSON */ : ts.getEmitScriptTarget(compilationSettings);
133667
+ var oldBucketCount = buckets.size;
133587
133668
  var bucket = ts.getOrUpdate(buckets, key, function () { return new ts.Map(); });
133669
+ if (ts.tracing) {
133670
+ if (buckets.size > oldBucketCount) {
133671
+ // It is interesting, but not definitively problematic if a build requires multiple document registry buckets -
133672
+ // perhaps they are for two projects that don't have any overlap.
133673
+ // Bonus: these events can help us interpret the more interesting event below.
133674
+ ts.tracing.instant("session" /* Session */, "createdDocumentRegistryBucket", { configFilePath: compilationSettings.configFilePath, key: key });
133675
+ }
133676
+ // It is fairly suspicious to have one path in two buckets - you'd expect dependencies to have similar configurations.
133677
+ // If this occurs unexpectedly, the fix is likely to synchronize the project settings.
133678
+ // Skip .d.ts files to reduce noise (should also cover most of node_modules).
133679
+ var otherBucketKey = !ts.fileExtensionIs(path, ".d.ts" /* Dts */) &&
133680
+ ts.forEachEntry(buckets, function (bucket, bucketKey) { return bucketKey !== key && bucket.has(path) && bucketKey; });
133681
+ if (otherBucketKey) {
133682
+ ts.tracing.instant("session" /* Session */, "documentRegistryBucketOverlap", { path: path, key1: otherBucketKey, key2: key });
133683
+ }
133684
+ }
133588
133685
  var bucketEntry = bucket.get(path);
133589
133686
  var entry = bucketEntry && getDocumentRegistryEntry(bucketEntry, scriptKind);
133590
133687
  if (!entry && externalCache) {
@@ -145720,6 +145817,8 @@ var ts;
145720
145817
  case 179 /* ConstructorType */:
145721
145818
  case 174 /* ConstructSignature */:
145722
145819
  return getList(node.typeParameters) || getList(node.parameters);
145820
+ case 171 /* GetAccessor */:
145821
+ return getList(node.parameters);
145723
145822
  case 256 /* ClassDeclaration */:
145724
145823
  case 225 /* ClassExpression */:
145725
145824
  case 257 /* InterfaceDeclaration */:
@@ -153156,6 +153255,9 @@ var ts;
153156
153255
  case 172 /* SetAccessor */:
153157
153256
  // Setter must have a parameter
153158
153257
  return false;
153258
+ case 171 /* GetAccessor */:
153259
+ // Getter cannot have parameters
153260
+ return true;
153159
153261
  default:
153160
153262
  return ts.Debug.failBadSyntaxKind(parent);
153161
153263
  }
@@ -155766,10 +155868,12 @@ var ts;
155766
155868
  });
155767
155869
  function getInfo(sourceFile, pos) {
155768
155870
  var token = ts.getTokenAtPosition(sourceFile, pos);
155769
- var indexSignature = ts.cast(token.parent.parent, ts.isIndexSignatureDeclaration);
155770
- if (ts.isClassDeclaration(indexSignature.parent))
155871
+ var indexSignature = ts.tryCast(token.parent.parent, ts.isIndexSignatureDeclaration);
155872
+ if (!indexSignature)
155873
+ return undefined;
155874
+ var container = ts.isInterfaceDeclaration(indexSignature.parent) ? indexSignature.parent : ts.tryCast(indexSignature.parent.parent, ts.isTypeAliasDeclaration);
155875
+ if (!container)
155771
155876
  return undefined;
155772
- var container = ts.isInterfaceDeclaration(indexSignature.parent) ? indexSignature.parent : ts.cast(indexSignature.parent.parent, ts.isTypeAliasDeclaration);
155773
155877
  return { indexSignature: indexSignature, container: container };
155774
155878
  }
155775
155879
  function createTypeAliasFromInterface(declaration, type) {
@@ -157360,8 +157464,8 @@ var ts;
157360
157464
  // but a super *method call* simply implies a 'this' reference
157361
157465
  if (node.parent.kind === 207 /* CallExpression */) {
157362
157466
  // Super constructor call
157363
- var containingClass_1 = ts.getContainingClass(node); // TODO:GH#18217
157364
- if (containingClass_1.pos < span.start || containingClass_1.end >= (span.start + span.length)) {
157467
+ var containingClass_1 = ts.getContainingClass(node);
157468
+ if (containingClass_1 === undefined || containingClass_1.pos < span.start || containingClass_1.end >= (span.start + span.length)) {
157365
157469
  (errors || (errors = [])).push(ts.createDiagnosticForNode(node, Messages.cannotExtractSuper));
157366
157470
  return true;
157367
157471
  }