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.
@@ -89,7 +89,7 @@ var ts;
89
89
  // The following is baselined as a literal template type without intervention
90
90
  /** The version of the TypeScript compiler release */
91
91
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
92
- ts.version = ts.versionMajorMinor + ".0-dev.20220206";
92
+ ts.version = ts.versionMajorMinor + ".0-dev.20220210";
93
93
  /* @internal */
94
94
  var Comparison;
95
95
  (function (Comparison) {
@@ -8034,10 +8034,10 @@ var ts;
8034
8034
  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
8035
  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
8036
  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."),
8037
+ 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."),
8038
+ 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
8039
  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."),
8040
+ 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
8041
  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
8042
  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
8043
  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."),
@@ -8205,6 +8205,8 @@ var ts;
8205
8205
  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
8206
  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
8207
  catch_or_finally_expected: diag(1472, ts.DiagnosticCategory.Error, "catch_or_finally_expected_1472", "'catch' or 'finally' expected."),
8208
+ 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."),
8209
+ 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
8210
  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
8211
  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
8212
  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),
@@ -13886,6 +13888,10 @@ var ts;
13886
13888
  return undefined;
13887
13889
  }
13888
13890
  ts.getDeclarationOfKind = getDeclarationOfKind;
13891
+ function getDeclarationsOfKind(symbol, kind) {
13892
+ return ts.filter(symbol.declarations || ts.emptyArray, function (d) { return d.kind === kind; });
13893
+ }
13894
+ ts.getDeclarationsOfKind = getDeclarationsOfKind;
13889
13895
  function createSymbolTable(symbols) {
13890
13896
  var result = new ts.Map();
13891
13897
  if (symbols) {
@@ -14121,6 +14127,10 @@ var ts;
14121
14127
  return getSourceFileOfNode(module.valueDeclaration || getNonAugmentationDeclaration(module));
14122
14128
  }
14123
14129
  ts.getSourceFileOfModule = getSourceFileOfModule;
14130
+ function isPlainJsFile(file, checkJs) {
14131
+ return !!file && (file.scriptKind === 1 /* JS */ || file.scriptKind === 2 /* JSX */) && !file.checkJsDirective && checkJs === undefined;
14132
+ }
14133
+ ts.isPlainJsFile = isPlainJsFile;
14124
14134
  function isStatementWithLocals(node) {
14125
14135
  switch (node.kind) {
14126
14136
  case 234 /* Block */:
@@ -46898,6 +46908,9 @@ var ts;
46898
46908
  CheckMode[CheckMode["SkipContextSensitive"] = 4] = "SkipContextSensitive";
46899
46909
  CheckMode[CheckMode["SkipGenericFunctions"] = 8] = "SkipGenericFunctions";
46900
46910
  CheckMode[CheckMode["IsForSignatureHelp"] = 16] = "IsForSignatureHelp";
46911
+ CheckMode[CheckMode["RestBindingElement"] = 32] = "RestBindingElement";
46912
+ // e.g. in `const { a, ...rest } = foo`, when checking the type of `foo` to determine the type of `rest`,
46913
+ // we need to preserve generic types instead of substituting them for constraints
46901
46914
  })(CheckMode || (CheckMode = {}));
46902
46915
  var SignatureCheckMode;
46903
46916
  (function (SignatureCheckMode) {
@@ -47950,13 +47963,13 @@ var ts;
47950
47963
  else { // error
47951
47964
  var isEitherEnum = !!(target.flags & 384 /* Enum */ || source.flags & 384 /* Enum */);
47952
47965
  var isEitherBlockScoped_1 = !!(target.flags & 2 /* BlockScopedVariable */ || source.flags & 2 /* BlockScopedVariable */);
47953
- var message = isEitherEnum
47954
- ? ts.Diagnostics.Enum_declarations_can_only_merge_with_namespace_or_other_enum_declarations
47955
- : isEitherBlockScoped_1
47956
- ? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0
47966
+ var message = isEitherEnum ? ts.Diagnostics.Enum_declarations_can_only_merge_with_namespace_or_other_enum_declarations
47967
+ : isEitherBlockScoped_1 ? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0
47957
47968
  : ts.Diagnostics.Duplicate_identifier_0;
47958
47969
  var sourceSymbolFile = source.declarations && ts.getSourceFileOfNode(source.declarations[0]);
47959
47970
  var targetSymbolFile = target.declarations && ts.getSourceFileOfNode(target.declarations[0]);
47971
+ var isSourcePlainJs = ts.isPlainJsFile(sourceSymbolFile, compilerOptions.checkJs);
47972
+ var isTargetPlainJs = ts.isPlainJsFile(targetSymbolFile, compilerOptions.checkJs);
47960
47973
  var symbolName_1 = symbolToString(source);
47961
47974
  // Collect top-level duplicate identifier errors into one mapping, so we can then merge their diagnostics if there are a bunch
47962
47975
  if (sourceSymbolFile && targetSymbolFile && amalgamatedDuplicates && !isEitherEnum && sourceSymbolFile !== targetSymbolFile) {
@@ -47968,12 +47981,16 @@ var ts;
47968
47981
  var conflictingSymbolInfo = ts.getOrUpdate(filesDuplicates.conflictingSymbols, symbolName_1, function () {
47969
47982
  return ({ isBlockScoped: isEitherBlockScoped_1, firstFileLocations: [], secondFileLocations: [] });
47970
47983
  });
47971
- addDuplicateLocations(conflictingSymbolInfo.firstFileLocations, source);
47972
- addDuplicateLocations(conflictingSymbolInfo.secondFileLocations, target);
47984
+ if (!isSourcePlainJs)
47985
+ addDuplicateLocations(conflictingSymbolInfo.firstFileLocations, source);
47986
+ if (!isTargetPlainJs)
47987
+ addDuplicateLocations(conflictingSymbolInfo.secondFileLocations, target);
47973
47988
  }
47974
47989
  else {
47975
- addDuplicateDeclarationErrorsForSymbols(source, message, symbolName_1, target);
47976
- addDuplicateDeclarationErrorsForSymbols(target, message, symbolName_1, source);
47990
+ if (!isSourcePlainJs)
47991
+ addDuplicateDeclarationErrorsForSymbols(source, message, symbolName_1, target);
47992
+ if (!isTargetPlainJs)
47993
+ addDuplicateDeclarationErrorsForSymbols(target, message, symbolName_1, source);
47977
47994
  }
47978
47995
  }
47979
47996
  return target;
@@ -48430,6 +48447,8 @@ var ts;
48430
48447
  // type parameters are visible in parameter list, return type and type parameter list
48431
48448
  ? lastLocation === location.type ||
48432
48449
  lastLocation.kind === 163 /* Parameter */ ||
48450
+ lastLocation.kind === 338 /* JSDocParameterTag */ ||
48451
+ lastLocation.kind === 339 /* JSDocReturnTag */ ||
48433
48452
  lastLocation.kind === 162 /* TypeParameter */
48434
48453
  // local types not visible outside the function body
48435
48454
  : false;
@@ -48689,9 +48708,9 @@ var ts;
48689
48708
  lastSelfReferenceLocation = location;
48690
48709
  }
48691
48710
  lastLocation = location;
48692
- location = ts.isJSDocTemplateTag(location) ?
48693
- ts.getEffectiveContainerForJSDocTemplateTag(location) || location.parent :
48694
- location.parent;
48711
+ location = ts.isJSDocTemplateTag(location) ? ts.getEffectiveContainerForJSDocTemplateTag(location) || location.parent :
48712
+ ts.isJSDocParameterTag(location) || ts.isJSDocReturnTag(location) ? ts.getHostSignatureFromJSDoc(location) || location.parent :
48713
+ location.parent;
48695
48714
  }
48696
48715
  // We just climbed up parents looking for the name, meaning that we started in a descendant node of `lastLocation`.
48697
48716
  // If `result === lastSelfReferenceLocation.symbol`, that means that we are somewhere inside `lastSelfReferenceLocation` looking up a name, and resolving to `lastLocation` itself.
@@ -49825,16 +49844,20 @@ var ts;
49825
49844
  return;
49826
49845
  }
49827
49846
  var host = ts.getJSDocHost(node);
49828
- if (host &&
49829
- ts.isExpressionStatement(host) &&
49830
- ts.isBinaryExpression(host.expression) &&
49831
- ts.getAssignmentDeclarationKind(host.expression) === 3 /* PrototypeProperty */) {
49832
- // X.prototype.m = /** @param {K} p */ function () { } <-- look for K on X's declaration
49847
+ if (host && ts.isExpressionStatement(host) && ts.isPrototypePropertyAssignment(host.expression)) {
49848
+ // /** @param {K} p */ X.prototype.m = function () { } <-- look for K on X's declaration
49833
49849
  var symbol = getSymbolOfNode(host.expression.left);
49834
49850
  if (symbol) {
49835
49851
  return getDeclarationOfJSPrototypeContainer(symbol);
49836
49852
  }
49837
49853
  }
49854
+ if (host && ts.isFunctionExpression(host) && ts.isPrototypePropertyAssignment(host.parent) && ts.isExpressionStatement(host.parent.parent)) {
49855
+ // X.prototype.m = /** @param {K} p */ function () { } <-- look for K on X's declaration
49856
+ var symbol = getSymbolOfNode(host.parent.left);
49857
+ if (symbol) {
49858
+ return getDeclarationOfJSPrototypeContainer(symbol);
49859
+ }
49860
+ }
49838
49861
  if (host && (ts.isObjectLiteralMethod(host) || ts.isPropertyAssignment(host)) &&
49839
49862
  ts.isBinaryExpression(host.parent.parent) &&
49840
49863
  ts.getAssignmentDeclarationKind(host.parent.parent) === 6 /* Prototype */) {
@@ -54321,9 +54344,12 @@ var ts;
54321
54344
  }
54322
54345
  // Return the type of a binding element parent. We check SymbolLinks first to see if a type has been
54323
54346
  // assigned by contextual typing.
54324
- function getTypeForBindingElementParent(node) {
54347
+ function getTypeForBindingElementParent(node, checkMode) {
54348
+ if (checkMode !== 0 /* Normal */) {
54349
+ return getTypeForVariableLikeDeclaration(node, /*includeOptionality*/ false, checkMode);
54350
+ }
54325
54351
  var symbol = getSymbolOfNode(node);
54326
- return symbol && getSymbolLinks(symbol).type || getTypeForVariableLikeDeclaration(node, /*includeOptionality*/ false);
54352
+ return symbol && getSymbolLinks(symbol).type || getTypeForVariableLikeDeclaration(node, /*includeOptionality*/ false, checkMode);
54327
54353
  }
54328
54354
  function getRestType(source, properties, symbol) {
54329
54355
  source = filterType(source, function (t) { return !(t.flags & 98304 /* Nullable */); });
@@ -54441,7 +54467,8 @@ var ts;
54441
54467
  }
54442
54468
  /** Return the inferred type for a binding element */
54443
54469
  function getTypeForBindingElement(declaration) {
54444
- var parentType = getTypeForBindingElementParent(declaration.parent.parent);
54470
+ var checkMode = declaration.dotDotDotToken ? 32 /* RestBindingElement */ : 0 /* Normal */;
54471
+ var parentType = getTypeForBindingElementParent(declaration.parent.parent, checkMode);
54445
54472
  return parentType && getBindingElementTypeFromParentType(declaration, parentType);
54446
54473
  }
54447
54474
  function getBindingElementTypeFromParentType(declaration, parentType) {
@@ -54513,9 +54540,9 @@ var ts;
54513
54540
  if (ts.getEffectiveTypeAnnotationNode(ts.walkUpBindingElementsAndPatterns(declaration))) {
54514
54541
  // In strict null checking mode, if a default value of a non-undefined type is specified, remove
54515
54542
  // undefined from the final type.
54516
- return strictNullChecks && !(getFalsyFlags(checkDeclarationInitializer(declaration)) & 32768 /* Undefined */) ? getNonUndefinedType(type) : type;
54543
+ return strictNullChecks && !(getFalsyFlags(checkDeclarationInitializer(declaration, 0 /* Normal */)) & 32768 /* Undefined */) ? getNonUndefinedType(type) : type;
54517
54544
  }
54518
- return widenTypeInferredFromInitializer(declaration, getUnionType([getNonUndefinedType(type), checkDeclarationInitializer(declaration)], 2 /* Subtype */));
54545
+ return widenTypeInferredFromInitializer(declaration, getUnionType([getNonUndefinedType(type), checkDeclarationInitializer(declaration, 0 /* Normal */)], 2 /* Subtype */));
54519
54546
  }
54520
54547
  function getTypeForDeclarationFromJSDocComment(declaration) {
54521
54548
  var jsdocType = ts.getJSDocType(declaration);
@@ -54538,11 +54565,11 @@ var ts;
54538
54565
  return strictNullChecks && isOptional ? getOptionalType(type, isProperty) : type;
54539
54566
  }
54540
54567
  // Return the inferred type for a variable, parameter, or property declaration
54541
- function getTypeForVariableLikeDeclaration(declaration, includeOptionality) {
54568
+ function getTypeForVariableLikeDeclaration(declaration, includeOptionality, checkMode) {
54542
54569
  // A variable declared in a for..in statement is of type string, or of type keyof T when the
54543
54570
  // right hand expression is of a type parameter type.
54544
54571
  if (ts.isVariableDeclaration(declaration) && declaration.parent.parent.kind === 242 /* ForInStatement */) {
54545
- var indexType = getIndexType(getNonNullableTypeIfNeeded(checkExpression(declaration.parent.parent.expression)));
54572
+ var indexType = getIndexType(getNonNullableTypeIfNeeded(checkExpression(declaration.parent.parent.expression, /*checkMode*/ checkMode)));
54546
54573
  return indexType.flags & (262144 /* TypeParameter */ | 4194304 /* Index */) ? getExtractStringType(indexType) : stringType;
54547
54574
  }
54548
54575
  if (ts.isVariableDeclaration(declaration) && declaration.parent.parent.kind === 243 /* ForOfStatement */) {
@@ -54619,7 +54646,7 @@ var ts;
54619
54646
  return containerObjectType;
54620
54647
  }
54621
54648
  }
54622
- var type = widenTypeInferredFromInitializer(declaration, checkDeclarationInitializer(declaration));
54649
+ var type = widenTypeInferredFromInitializer(declaration, checkDeclarationInitializer(declaration, checkMode));
54623
54650
  return addOptionality(type, isProperty, isOptional);
54624
54651
  }
54625
54652
  if (ts.isPropertyDeclaration(declaration) && (noImplicitAny || ts.isInJSFile(declaration))) {
@@ -54991,7 +55018,7 @@ var ts;
54991
55018
  // contextual type or, if the element itself is a binding pattern, with the type implied by that binding
54992
55019
  // pattern.
54993
55020
  var contextualType = ts.isBindingPattern(element.name) ? getTypeFromBindingPattern(element.name, /*includePatternInType*/ true, /*reportErrors*/ false) : unknownType;
54994
- return addOptionality(widenTypeInferredFromInitializer(element, checkDeclarationInitializer(element, contextualType)));
55021
+ return addOptionality(widenTypeInferredFromInitializer(element, checkDeclarationInitializer(element, 0 /* Normal */, contextualType)));
54995
55022
  }
54996
55023
  if (ts.isBindingPattern(element.name)) {
54997
55024
  return getTypeFromBindingPattern(element.name, includePatternInType, reportErrors);
@@ -55080,7 +55107,7 @@ var ts;
55080
55107
  // binding pattern [x, s = ""]. Because the contextual type is a tuple type, the resulting type of [1, "one"] is the
55081
55108
  // tuple type [number, string]. Thus, the type inferred for 'x' is number and the type inferred for 's' is string.
55082
55109
  function getWidenedTypeForVariableLikeDeclaration(declaration, reportErrors) {
55083
- return widenTypeForVariableLikeDeclaration(getTypeForVariableLikeDeclaration(declaration, /*includeOptionality*/ true), declaration, reportErrors);
55110
+ return widenTypeForVariableLikeDeclaration(getTypeForVariableLikeDeclaration(declaration, /*includeOptionality*/ true, 0 /* Normal */), declaration, reportErrors);
55084
55111
  }
55085
55112
  function isGlobalSymbolConstructor(node) {
55086
55113
  var symbol = getSymbolOfNode(node);
@@ -55309,10 +55336,12 @@ var ts;
55309
55336
  if (writing === void 0) { writing = false; }
55310
55337
  var getter = ts.getDeclarationOfKind(symbol, 171 /* GetAccessor */);
55311
55338
  var setter = ts.getDeclarationOfKind(symbol, 172 /* SetAccessor */);
55312
- var setterType = getAnnotatedAccessorType(setter);
55313
55339
  // For write operations, prioritize type annotations on the setter
55314
- if (writing && setterType) {
55315
- return instantiateTypeIfNeeded(setterType, symbol);
55340
+ if (writing) {
55341
+ var setterType_1 = getAnnotatedAccessorType(setter);
55342
+ if (setterType_1) {
55343
+ return instantiateTypeIfNeeded(setterType_1, symbol);
55344
+ }
55316
55345
  }
55317
55346
  // Else defer to the getter type
55318
55347
  if (getter && ts.isInJSFile(getter)) {
@@ -55327,6 +55356,7 @@ var ts;
55327
55356
  return instantiateTypeIfNeeded(getterType, symbol);
55328
55357
  }
55329
55358
  // If the user didn't specify a return type, try to use the set-accessor's parameter type.
55359
+ var setterType = getAnnotatedAccessorType(setter);
55330
55360
  if (setterType) {
55331
55361
  return setterType;
55332
55362
  }
@@ -55475,6 +55505,39 @@ var ts;
55475
55505
  }
55476
55506
  return links.type;
55477
55507
  }
55508
+ function getWriteTypeOfSymbolWithDeferredType(symbol) {
55509
+ var links = getSymbolLinks(symbol);
55510
+ if (!links.writeType && links.deferralWriteConstituents) {
55511
+ ts.Debug.assertIsDefined(links.deferralParent);
55512
+ ts.Debug.assertIsDefined(links.deferralConstituents);
55513
+ links.writeType = links.deferralParent.flags & 1048576 /* Union */ ? getUnionType(links.deferralWriteConstituents) : getIntersectionType(links.deferralWriteConstituents);
55514
+ }
55515
+ return links.writeType;
55516
+ }
55517
+ /**
55518
+ * Distinct write types come only from set accessors, but union and intersection
55519
+ * properties deriving from set accessors will either pre-compute or defer the
55520
+ * union or intersection of the writeTypes of their constituents. To account for
55521
+ * this, we will assume that any deferred type or transient symbol may have a
55522
+ * `writeType` (or a deferred write type ready to be computed) that should be
55523
+ * used before looking for set accessor declarations.
55524
+ */
55525
+ function getWriteTypeOfSymbol(symbol) {
55526
+ var checkFlags = ts.getCheckFlags(symbol);
55527
+ if (checkFlags & 65536 /* DeferredType */) {
55528
+ var writeType = getWriteTypeOfSymbolWithDeferredType(symbol);
55529
+ if (writeType) {
55530
+ return writeType;
55531
+ }
55532
+ }
55533
+ if (symbol.flags & 33554432 /* Transient */) {
55534
+ var writeType = symbol.writeType;
55535
+ if (writeType) {
55536
+ return writeType;
55537
+ }
55538
+ }
55539
+ return getSetAccessorTypeOfSymbol(symbol);
55540
+ }
55478
55541
  function getSetAccessorTypeOfSymbol(symbol) {
55479
55542
  if (symbol.flags & 98304 /* Accessor */) {
55480
55543
  var type = getTypeOfSetAccessor(symbol);
@@ -57845,6 +57908,7 @@ var ts;
57845
57908
  var firstType;
57846
57909
  var nameType;
57847
57910
  var propTypes = [];
57911
+ var writeTypes;
57848
57912
  var firstValueDeclaration;
57849
57913
  var hasNonUniformValueDeclaration = false;
57850
57914
  for (var _d = 0, props_1 = props; _d < props_1.length; _d++) {
@@ -57861,6 +57925,10 @@ var ts;
57861
57925
  firstType = type;
57862
57926
  nameType = getSymbolLinks(prop).nameType;
57863
57927
  }
57928
+ var writeType = getWriteTypeOfSymbol(prop);
57929
+ if (writeTypes || writeType !== type) {
57930
+ writeTypes = ts.append(!writeTypes ? propTypes.slice() : writeTypes, writeType);
57931
+ }
57864
57932
  else if (type !== firstType) {
57865
57933
  checkFlags |= 64 /* HasNonUniformType */;
57866
57934
  }
@@ -57889,9 +57957,13 @@ var ts;
57889
57957
  result.checkFlags |= 65536 /* DeferredType */;
57890
57958
  result.deferralParent = containingType;
57891
57959
  result.deferralConstituents = propTypes;
57960
+ result.deferralWriteConstituents = writeTypes;
57892
57961
  }
57893
57962
  else {
57894
57963
  result.type = isUnion ? getUnionType(propTypes) : getIntersectionType(propTypes);
57964
+ if (writeTypes) {
57965
+ result.writeType = isUnion ? getUnionType(writeTypes) : getIntersectionType(writeTypes);
57966
+ }
57895
57967
  }
57896
57968
  return result;
57897
57969
  }
@@ -59033,7 +59105,7 @@ var ts;
59033
59105
  }
59034
59106
  function getImpliedConstraint(type, checkNode, extendsNode) {
59035
59107
  return isUnaryTupleTypeNode(checkNode) && isUnaryTupleTypeNode(extendsNode) ? getImpliedConstraint(type, checkNode.elements[0], extendsNode.elements[0]) :
59036
- getActualTypeVariable(getTypeFromTypeNode(checkNode)) === type ? getTypeFromTypeNode(extendsNode) :
59108
+ getActualTypeVariable(getTypeFromTypeNode(checkNode)) === getActualTypeVariable(type) ? getTypeFromTypeNode(extendsNode) :
59037
59109
  undefined;
59038
59110
  }
59039
59111
  function getConditionalFlowTypeOfType(type, node) {
@@ -69842,12 +69914,16 @@ var ts;
69842
69914
  function isGenericTypeWithoutNullableConstraint(type) {
69843
69915
  return !!(type.flags & 465829888 /* Instantiable */ && !maybeTypeOfKind(getBaseConstraintOrType(type), 98304 /* Nullable */));
69844
69916
  }
69845
- function hasNonBindingPatternContextualTypeWithNoGenericTypes(node) {
69917
+ function hasContextualTypeWithNoGenericTypes(node, checkMode) {
69846
69918
  // Computing the contextual type for a child of a JSX element involves resolving the type of the
69847
69919
  // element's tag name, so we exclude that here to avoid circularities.
69920
+ // If check mode has `CheckMode.RestBindingElement`, we skip binding pattern contextual types,
69921
+ // as we want the type of a rest element to be generic when possible.
69848
69922
  var contextualType = (ts.isIdentifier(node) || ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node)) &&
69849
69923
  !((ts.isJsxOpeningElement(node.parent) || ts.isJsxSelfClosingElement(node.parent)) && node.parent.tagName === node) &&
69850
- getContextualType(node, 8 /* SkipBindingPatterns */);
69924
+ (checkMode && checkMode & 32 /* RestBindingElement */ ?
69925
+ getContextualType(node, 8 /* SkipBindingPatterns */)
69926
+ : getContextualType(node));
69851
69927
  return contextualType && !isGenericType(contextualType);
69852
69928
  }
69853
69929
  function getNarrowableTypeForReference(type, reference, checkMode) {
@@ -69860,7 +69936,7 @@ var ts;
69860
69936
  // 'string | undefined' to give control flow analysis the opportunity to narrow to type 'string'.
69861
69937
  var substituteConstraints = !(checkMode && checkMode & 2 /* Inferential */) &&
69862
69938
  someType(type, isGenericTypeWithUnionConstraint) &&
69863
- (isConstraintPosition(type, reference) || hasNonBindingPatternContextualTypeWithNoGenericTypes(reference));
69939
+ (isConstraintPosition(type, reference) || hasContextualTypeWithNoGenericTypes(reference, checkMode));
69864
69940
  return substituteConstraints ? mapType(type, function (t) { return t.flags & 465829888 /* Instantiable */ && !isMappedTypeGenericIndexedAccess(t) ? getBaseConstraintOrType(t) : t; }) : type;
69865
69941
  }
69866
69942
  function isExportOrExportExpression(location) {
@@ -69928,7 +70004,7 @@ var ts;
69928
70004
  var links = getNodeLinks(location);
69929
70005
  if (!(links.flags & 268435456 /* InCheckIdentifier */)) {
69930
70006
  links.flags |= 268435456 /* InCheckIdentifier */;
69931
- var parentType = getTypeForBindingElementParent(parent);
70007
+ var parentType = getTypeForBindingElementParent(parent, 0 /* Normal */);
69932
70008
  links.flags &= ~268435456 /* InCheckIdentifier */;
69933
70009
  if (parentType && parentType.flags & 1048576 /* Union */ && !(parent.kind === 163 /* Parameter */ && isSymbolAssigned(symbol))) {
69934
70010
  var pattern = declaration.parent;
@@ -70781,7 +70857,7 @@ var ts;
70781
70857
  var parent = declaration.parent.parent;
70782
70858
  var name = declaration.propertyName || declaration.name;
70783
70859
  var parentType = getContextualTypeForVariableLikeDeclaration(parent) ||
70784
- parent.kind !== 202 /* BindingElement */ && parent.initializer && checkDeclarationInitializer(parent);
70860
+ parent.kind !== 202 /* BindingElement */ && parent.initializer && checkDeclarationInitializer(parent, declaration.dotDotDotToken ? 32 /* RestBindingElement */ : 0 /* Normal */);
70785
70861
  if (!parentType || ts.isBindingPattern(name) || ts.isComputedNonLiteralName(name))
70786
70862
  return undefined;
70787
70863
  if (parent.name.kind === 201 /* ArrayBindingPattern */) {
@@ -73022,7 +73098,7 @@ var ts;
73022
73098
  error(right, ts.Diagnostics.Cannot_assign_to_0_because_it_is_a_read_only_property, ts.idText(right));
73023
73099
  return errorType;
73024
73100
  }
73025
- propType = isThisPropertyAccessInConstructor(node, prop) ? autoType : writing ? getSetAccessorTypeOfSymbol(prop) : getTypeOfSymbol(prop);
73101
+ propType = isThisPropertyAccessInConstructor(node, prop) ? autoType : writing ? getWriteTypeOfSymbol(prop) : getTypeOfSymbol(prop);
73026
73102
  }
73027
73103
  return getFlowTypeOfAccessExpression(node, prop, propType, right, checkMode);
73028
73104
  }
@@ -75947,7 +76023,7 @@ var ts;
75947
76023
  var links = getSymbolLinks(parameter);
75948
76024
  if (!links.type) {
75949
76025
  var declaration = parameter.valueDeclaration;
75950
- links.type = type || getWidenedTypeForVariableLikeDeclaration(declaration, /*includeOptionality*/ true);
76026
+ links.type = type || getWidenedTypeForVariableLikeDeclaration(declaration, /*reportErrors*/ true);
75951
76027
  if (declaration.name.kind !== 79 /* Identifier */) {
75952
76028
  // if inference didn't come up with anything but unknown, fall back to the binding pattern if present.
75953
76029
  if (links.type === unknownType) {
@@ -77678,11 +77754,11 @@ var ts;
77678
77754
  }
77679
77755
  }
77680
77756
  function checkExpressionCached(node, checkMode) {
77757
+ if (checkMode && checkMode !== 0 /* Normal */) {
77758
+ return checkExpression(node, checkMode);
77759
+ }
77681
77760
  var links = getNodeLinks(node);
77682
77761
  if (!links.resolvedType) {
77683
- if (checkMode && checkMode !== 0 /* Normal */) {
77684
- return checkExpression(node, checkMode);
77685
- }
77686
77762
  // When computing a type that we're going to cache, we need to ignore any ongoing control flow
77687
77763
  // analysis because variables may have transient types in indeterminable states. Moving flowLoopStart
77688
77764
  // to the top of the stack ensures all transient types are computed from a known point.
@@ -77702,10 +77778,12 @@ var ts;
77702
77778
  node.kind === 228 /* AsExpression */ ||
77703
77779
  ts.isJSDocTypeAssertion(node);
77704
77780
  }
77705
- function checkDeclarationInitializer(declaration, contextualType) {
77781
+ function checkDeclarationInitializer(declaration, checkMode, contextualType) {
77706
77782
  var initializer = ts.getEffectiveInitializer(declaration);
77707
77783
  var type = getQuickTypeOfExpression(initializer) ||
77708
- (contextualType ? checkExpressionWithContextualType(initializer, contextualType, /*inferenceContext*/ undefined, 0 /* Normal */) : checkExpressionCached(initializer));
77784
+ (contextualType ?
77785
+ checkExpressionWithContextualType(initializer, contextualType, /*inferenceContext*/ undefined, checkMode || 0 /* Normal */)
77786
+ : checkExpressionCached(initializer, checkMode));
77709
77787
  return ts.isParameter(declaration) && declaration.name.kind === 201 /* ArrayBindingPattern */ &&
77710
77788
  isTupleType(type) && !type.target.hasRestElement && getTypeReferenceArity(type) < declaration.name.elements.length ?
77711
77789
  padTupleType(type, declaration.name) : type;
@@ -80642,7 +80720,8 @@ var ts;
80642
80720
  }
80643
80721
  // check private/protected variable access
80644
80722
  var parent = node.parent.parent;
80645
- var parentType = getTypeForBindingElementParent(parent);
80723
+ var parentCheckMode = node.dotDotDotToken ? 32 /* RestBindingElement */ : 0 /* Normal */;
80724
+ var parentType = getTypeForBindingElementParent(parent, parentCheckMode);
80646
80725
  var name = node.propertyName || node.name;
80647
80726
  if (parentType && !ts.isBindingPattern(name)) {
80648
80727
  var exprType = getLiteralTypeFromPropertyName(name);
@@ -81881,7 +81960,7 @@ var ts;
81881
81960
  var declaration = catchClause.variableDeclaration;
81882
81961
  var typeNode = ts.getEffectiveTypeAnnotationNode(ts.getRootDeclaration(declaration));
81883
81962
  if (typeNode) {
81884
- var type = getTypeForVariableLikeDeclaration(declaration, /*includeOptionality*/ false);
81963
+ var type = getTypeForVariableLikeDeclaration(declaration, /*includeOptionality*/ false, 0 /* Normal */);
81885
81964
  if (type && !(type.flags & 3 /* AnyOrUnknown */)) {
81886
81965
  grammarErrorOnFirstToken(typeNode, ts.Diagnostics.Catch_clause_variable_type_annotation_must_be_any_or_unknown_if_specified);
81887
81966
  }
@@ -82987,7 +83066,7 @@ var ts;
82987
83066
  var isAmbientExternalModule = ts.isAmbientModule(node);
82988
83067
  var contextErrorMessage = isAmbientExternalModule
82989
83068
  ? ts.Diagnostics.An_ambient_module_declaration_is_only_allowed_at_the_top_level_in_a_file
82990
- : ts.Diagnostics.A_namespace_declaration_is_only_allowed_in_a_namespace_or_module;
83069
+ : ts.Diagnostics.A_namespace_declaration_is_only_allowed_at_the_top_level_of_a_namespace_or_module;
82991
83070
  if (checkGrammarModuleElementContext(node, contextErrorMessage)) {
82992
83071
  // If we hit a module declaration in an illegal context, just bail out to avoid cascading errors.
82993
83072
  return;
@@ -83303,7 +83382,7 @@ var ts;
83303
83382
  }
83304
83383
  }
83305
83384
  function checkImportDeclaration(node) {
83306
- if (checkGrammarModuleElementContext(node, ts.Diagnostics.An_import_declaration_can_only_be_used_in_a_namespace_or_module)) {
83385
+ 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)) {
83307
83386
  // If we hit an import declaration in an illegal context, just bail out to avoid cascading errors.
83308
83387
  return;
83309
83388
  }
@@ -83336,7 +83415,7 @@ var ts;
83336
83415
  checkAssertClause(node);
83337
83416
  }
83338
83417
  function checkImportEqualsDeclaration(node) {
83339
- if (checkGrammarModuleElementContext(node, ts.Diagnostics.An_import_declaration_can_only_be_used_in_a_namespace_or_module)) {
83418
+ 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)) {
83340
83419
  // If we hit an import declaration in an illegal context, just bail out to avoid cascading errors.
83341
83420
  return;
83342
83421
  }
@@ -83373,7 +83452,7 @@ var ts;
83373
83452
  }
83374
83453
  }
83375
83454
  function checkExportDeclaration(node) {
83376
- if (checkGrammarModuleElementContext(node, ts.Diagnostics.An_export_declaration_can_only_be_used_in_a_module)) {
83455
+ 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)) {
83377
83456
  // If we hit an export in an illegal context, just bail out to avoid cascading errors.
83378
83457
  return;
83379
83458
  }
@@ -84607,7 +84686,7 @@ var ts;
84607
84686
  return errorType;
84608
84687
  }
84609
84688
  if (ts.isBindingPattern(node)) {
84610
- return getTypeForVariableLikeDeclaration(node.parent, /*includeOptionality*/ true) || errorType;
84689
+ return getTypeForVariableLikeDeclaration(node.parent, /*includeOptionality*/ true, 0 /* Normal */) || errorType;
84611
84690
  }
84612
84691
  if (isInRightSideOfImportOrExportAssignment(node)) {
84613
84692
  var symbol = getSymbolAtLocation(node);
@@ -114354,9 +114433,9 @@ var ts;
114354
114433
  ts.Diagnostics.A_return_statement_cannot_be_used_inside_a_class_static_block.code,
114355
114434
  ts.Diagnostics.A_set_accessor_cannot_have_rest_parameter.code,
114356
114435
  ts.Diagnostics.A_set_accessor_must_have_exactly_one_parameter.code,
114357
- ts.Diagnostics.An_export_declaration_can_only_be_used_in_a_module.code,
114436
+ ts.Diagnostics.An_export_declaration_can_only_be_used_at_the_top_level_of_a_module.code,
114358
114437
  ts.Diagnostics.An_export_declaration_cannot_have_modifiers.code,
114359
- ts.Diagnostics.An_import_declaration_can_only_be_used_in_a_namespace_or_module.code,
114438
+ ts.Diagnostics.An_import_declaration_can_only_be_used_at_the_top_level_of_a_module.code,
114360
114439
  ts.Diagnostics.An_import_declaration_cannot_have_modifiers.code,
114361
114440
  ts.Diagnostics.An_object_member_cannot_be_declared_optional.code,
114362
114441
  ts.Diagnostics.Argument_of_dynamic_import_cannot_be_spread_element.code,
@@ -115424,7 +115503,7 @@ var ts;
115424
115503
  ts.Debug.assert(!!sourceFile.bindDiagnostics);
115425
115504
  var isJs = sourceFile.scriptKind === 1 /* JS */ || sourceFile.scriptKind === 2 /* JSX */;
115426
115505
  var isCheckJs = isJs && ts.isCheckJsEnabledForFile(sourceFile, options);
115427
- var isPlainJs = isJs && !sourceFile.checkJsDirective && options.checkJs === undefined;
115506
+ var isPlainJs = ts.isPlainJsFile(sourceFile, options.checkJs);
115428
115507
  var isTsNoCheck = !!sourceFile.checkJsDirective && sourceFile.checkJsDirective.enabled === false;
115429
115508
  // By default, only type-check .ts, .tsx, Deferred, plain JS, checked JS and External
115430
115509
  // - plain JS: .js files with no // ts-check and checkJs: undefined
@@ -435,6 +435,7 @@
435
435
  "Convert_function_to_an_ES2015_class_95001": "将函数转换为 ES2015 类",
436
436
  "Convert_invalid_character_to_its_html_entity_code_95100": "将无效字符转换为其 HTML 实体代码",
437
437
  "Convert_named_export_to_default_export_95062": "将命名导出转换为默认导出",
438
+ "Convert_named_imports_to_default_import_95170": "将命名导入转换为默认导入",
438
439
  "Convert_named_imports_to_namespace_import_95057": "将命名导入转换为命名空间导入",
439
440
  "Convert_namespace_import_to_named_imports_95056": "将命名空间导入转换为命名导入",
440
441
  "Convert_overload_list_to_single_signature_95118": "将重载列表转换为单一签名",
@@ -1116,7 +1117,6 @@
1116
1117
  "Property_0_is_protected_in_type_1_but_public_in_type_2_2444": "属性“{0}”在类型“{1}”中受保护,但在类型“{2}”中为公共属性。",
1117
1118
  "Property_0_is_used_before_being_assigned_2565": "在赋值前使用了属性“{0}”。",
1118
1119
  "Property_0_is_used_before_its_initialization_2729": "属性 \"{0}\" 在其初始化前已被使用。",
1119
- "Property_0_may_not_be_used_in_a_static_property_s_initializer_in_the_same_class_when_target_is_esnex_2810": "当 “target” 为 “esnext” 且 “useDefineForClassFields” 为 ”false” 时,属性“{0}”不能用在同一类静态属性的初始化表达式中。",
1120
1120
  "Property_0_may_not_exist_on_type_1_Did_you_mean_2_2568": "类型“{1}”上不存在属性“{0}”。你是否是指“{2}”?",
1121
1121
  "Property_0_of_JSX_spread_attribute_is_not_assignable_to_target_property_2606": "JSX 展开特性的“{0}”属性不能分配给目标属性。",
1122
1122
  "Property_0_of_exported_class_expression_may_not_be_private_or_protected_4094": "导出类表达式的属性“{0}”可能不是私密或受保护的属性。",
@@ -1324,7 +1324,6 @@
1324
1324
  "Starting_compilation_in_watch_mode_6031": "在监视模式下开始编译...",
1325
1325
  "Statement_expected_1129": "应为语句。",
1326
1326
  "Statements_are_not_allowed_in_ambient_contexts_1036": "不允许在环境上下文中使用语句。",
1327
- "Static_fields_with_private_names_can_t_have_initializers_when_the_useDefineForClassFields_flag_is_no_2805": "若未使用 \"esnext\" 的 \"--target\" 指定 \"--useDefineForClassFields\" 标志,则具有专用名称的静态字段不能有初始值设定项。请考虑添加 \"--useDefineForClassFields\" 标志。",
1328
1327
  "Static_members_cannot_reference_class_type_parameters_2302": "静态成员不能引用类类型参数。",
1329
1328
  "Static_property_0_conflicts_with_built_in_property_Function_0_of_constructor_function_1_2699": "静态属性“{0}”与构造函数“{1}”的内置属性函数“{0}”冲突。",
1330
1329
  "String_literal_expected_1141": "应为字符串文本。",
@@ -435,6 +435,7 @@
435
435
  "Convert_function_to_an_ES2015_class_95001": "將函式轉換為 ES2015 類別",
436
436
  "Convert_invalid_character_to_its_html_entity_code_95100": "將無效字元轉換為其 HTML 實體代碼",
437
437
  "Convert_named_export_to_default_export_95062": "將具名匯出轉換為預設匯出",
438
+ "Convert_named_imports_to_default_import_95170": "將具名匯入轉換為預設匯入",
438
439
  "Convert_named_imports_to_namespace_import_95057": "將具名匯入轉換為命名空間匯入",
439
440
  "Convert_namespace_import_to_named_imports_95056": "將命名空間匯入轉換為具名匯入",
440
441
  "Convert_overload_list_to_single_signature_95118": "將多載清單轉換成單一特徵標記",
@@ -1116,7 +1117,6 @@
1116
1117
  "Property_0_is_protected_in_type_1_but_public_in_type_2_2444": "在類型 '{1}' 中,'{0}' 是受保護屬性,但在類型 '{2}' 中是公用屬性。",
1117
1118
  "Property_0_is_used_before_being_assigned_2565": "屬性 '{0}' 已在指派之前使用。",
1118
1119
  "Property_0_is_used_before_its_initialization_2729": "將屬性 '{0}' 初始化前已使用該屬性。",
1119
- "Property_0_may_not_be_used_in_a_static_property_s_initializer_in_the_same_class_when_target_is_esnex_2810": "當 'target' 為 'esnext' 且 'useDefineForClassFields' 為 'false' 時,不能在同一個類別的靜態屬性初始設定式中使用屬性 '{0}'。",
1120
1120
  "Property_0_may_not_exist_on_type_1_Did_you_mean_2_2568": "類型 '{1}' 可能不存在屬性 '{0}'。您指的是 '{2}' 嗎?",
1121
1121
  "Property_0_of_JSX_spread_attribute_is_not_assignable_to_target_property_2606": "JSX 擴張屬性 (Attribute) 的屬性 (Property) '{0}' 不可指派給目標屬性 (Property)。",
1122
1122
  "Property_0_of_exported_class_expression_may_not_be_private_or_protected_4094": "匯出之類別運算式的屬性 '{0}' 可能為私人或受保護。",
@@ -1324,7 +1324,6 @@
1324
1324
  "Starting_compilation_in_watch_mode_6031": "在監看模式中開始編譯...",
1325
1325
  "Statement_expected_1129": "必須是陳述式。",
1326
1326
  "Statements_are_not_allowed_in_ambient_contexts_1036": "環境內容中不得有陳述式。",
1327
- "Static_fields_with_private_names_can_t_have_initializers_when_the_useDefineForClassFields_flag_is_no_2805": "當 '--useDefineForClassFields' 旗標未以 'esnext' 的 '--target' 指定時,具有私人名稱的靜態欄位不得有初始設定式。請考慮新增 '--useDefineForClassFields' 旗標。",
1328
1327
  "Static_members_cannot_reference_class_type_parameters_2302": "靜態成員不得參考類別類型參數。",
1329
1328
  "Static_property_0_conflicts_with_built_in_property_Function_0_of_constructor_function_1_2699": "靜態屬性 '{0}' 與建構函式 '{1}' 的內建屬性 'Function.{0}' 相衝突。",
1330
1329
  "String_literal_expected_1141": "必須是字串常值。",
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "typescript",
3
3
  "author": "Microsoft Corp.",
4
4
  "homepage": "https://www.typescriptlang.org/",
5
- "version": "4.6.0-dev.20220206",
5
+ "version": "4.6.0-dev.20220210",
6
6
  "license": "Apache-2.0",
7
7
  "description": "TypeScript is a language for application scale JavaScript development",
8
8
  "keywords": [