typescript 4.6.0-dev.20220209 → 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.20220209";
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),
@@ -14125,6 +14127,10 @@ var ts;
14125
14127
  return getSourceFileOfNode(module.valueDeclaration || getNonAugmentationDeclaration(module));
14126
14128
  }
14127
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;
14128
14134
  function isStatementWithLocals(node) {
14129
14135
  switch (node.kind) {
14130
14136
  case 234 /* Block */:
@@ -46902,6 +46908,9 @@ var ts;
46902
46908
  CheckMode[CheckMode["SkipContextSensitive"] = 4] = "SkipContextSensitive";
46903
46909
  CheckMode[CheckMode["SkipGenericFunctions"] = 8] = "SkipGenericFunctions";
46904
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
46905
46914
  })(CheckMode || (CheckMode = {}));
46906
46915
  var SignatureCheckMode;
46907
46916
  (function (SignatureCheckMode) {
@@ -47954,13 +47963,13 @@ var ts;
47954
47963
  else { // error
47955
47964
  var isEitherEnum = !!(target.flags & 384 /* Enum */ || source.flags & 384 /* Enum */);
47956
47965
  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
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
47961
47968
  : ts.Diagnostics.Duplicate_identifier_0;
47962
47969
  var sourceSymbolFile = source.declarations && ts.getSourceFileOfNode(source.declarations[0]);
47963
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);
47964
47973
  var symbolName_1 = symbolToString(source);
47965
47974
  // Collect top-level duplicate identifier errors into one mapping, so we can then merge their diagnostics if there are a bunch
47966
47975
  if (sourceSymbolFile && targetSymbolFile && amalgamatedDuplicates && !isEitherEnum && sourceSymbolFile !== targetSymbolFile) {
@@ -47972,12 +47981,16 @@ var ts;
47972
47981
  var conflictingSymbolInfo = ts.getOrUpdate(filesDuplicates.conflictingSymbols, symbolName_1, function () {
47973
47982
  return ({ isBlockScoped: isEitherBlockScoped_1, firstFileLocations: [], secondFileLocations: [] });
47974
47983
  });
47975
- addDuplicateLocations(conflictingSymbolInfo.firstFileLocations, source);
47976
- addDuplicateLocations(conflictingSymbolInfo.secondFileLocations, target);
47984
+ if (!isSourcePlainJs)
47985
+ addDuplicateLocations(conflictingSymbolInfo.firstFileLocations, source);
47986
+ if (!isTargetPlainJs)
47987
+ addDuplicateLocations(conflictingSymbolInfo.secondFileLocations, target);
47977
47988
  }
47978
47989
  else {
47979
- addDuplicateDeclarationErrorsForSymbols(source, message, symbolName_1, target);
47980
- 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);
47981
47994
  }
47982
47995
  }
47983
47996
  return target;
@@ -48434,6 +48447,8 @@ var ts;
48434
48447
  // type parameters are visible in parameter list, return type and type parameter list
48435
48448
  ? lastLocation === location.type ||
48436
48449
  lastLocation.kind === 163 /* Parameter */ ||
48450
+ lastLocation.kind === 338 /* JSDocParameterTag */ ||
48451
+ lastLocation.kind === 339 /* JSDocReturnTag */ ||
48437
48452
  lastLocation.kind === 162 /* TypeParameter */
48438
48453
  // local types not visible outside the function body
48439
48454
  : false;
@@ -48693,9 +48708,9 @@ var ts;
48693
48708
  lastSelfReferenceLocation = location;
48694
48709
  }
48695
48710
  lastLocation = location;
48696
- location = ts.isJSDocTemplateTag(location) ?
48697
- ts.getEffectiveContainerForJSDocTemplateTag(location) || location.parent :
48698
- 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;
48699
48714
  }
48700
48715
  // We just climbed up parents looking for the name, meaning that we started in a descendant node of `lastLocation`.
48701
48716
  // If `result === lastSelfReferenceLocation.symbol`, that means that we are somewhere inside `lastSelfReferenceLocation` looking up a name, and resolving to `lastLocation` itself.
@@ -49829,16 +49844,20 @@ var ts;
49829
49844
  return;
49830
49845
  }
49831
49846
  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
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
49837
49849
  var symbol = getSymbolOfNode(host.expression.left);
49838
49850
  if (symbol) {
49839
49851
  return getDeclarationOfJSPrototypeContainer(symbol);
49840
49852
  }
49841
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
+ }
49842
49861
  if (host && (ts.isObjectLiteralMethod(host) || ts.isPropertyAssignment(host)) &&
49843
49862
  ts.isBinaryExpression(host.parent.parent) &&
49844
49863
  ts.getAssignmentDeclarationKind(host.parent.parent) === 6 /* Prototype */) {
@@ -54325,9 +54344,12 @@ var ts;
54325
54344
  }
54326
54345
  // Return the type of a binding element parent. We check SymbolLinks first to see if a type has been
54327
54346
  // assigned by contextual typing.
54328
- function getTypeForBindingElementParent(node) {
54347
+ function getTypeForBindingElementParent(node, checkMode) {
54348
+ if (checkMode !== 0 /* Normal */) {
54349
+ return getTypeForVariableLikeDeclaration(node, /*includeOptionality*/ false, checkMode);
54350
+ }
54329
54351
  var symbol = getSymbolOfNode(node);
54330
- return symbol && getSymbolLinks(symbol).type || getTypeForVariableLikeDeclaration(node, /*includeOptionality*/ false);
54352
+ return symbol && getSymbolLinks(symbol).type || getTypeForVariableLikeDeclaration(node, /*includeOptionality*/ false, checkMode);
54331
54353
  }
54332
54354
  function getRestType(source, properties, symbol) {
54333
54355
  source = filterType(source, function (t) { return !(t.flags & 98304 /* Nullable */); });
@@ -54445,7 +54467,8 @@ var ts;
54445
54467
  }
54446
54468
  /** Return the inferred type for a binding element */
54447
54469
  function getTypeForBindingElement(declaration) {
54448
- var parentType = getTypeForBindingElementParent(declaration.parent.parent);
54470
+ var checkMode = declaration.dotDotDotToken ? 32 /* RestBindingElement */ : 0 /* Normal */;
54471
+ var parentType = getTypeForBindingElementParent(declaration.parent.parent, checkMode);
54449
54472
  return parentType && getBindingElementTypeFromParentType(declaration, parentType);
54450
54473
  }
54451
54474
  function getBindingElementTypeFromParentType(declaration, parentType) {
@@ -54517,9 +54540,9 @@ var ts;
54517
54540
  if (ts.getEffectiveTypeAnnotationNode(ts.walkUpBindingElementsAndPatterns(declaration))) {
54518
54541
  // In strict null checking mode, if a default value of a non-undefined type is specified, remove
54519
54542
  // undefined from the final type.
54520
- return strictNullChecks && !(getFalsyFlags(checkDeclarationInitializer(declaration)) & 32768 /* Undefined */) ? getNonUndefinedType(type) : type;
54543
+ return strictNullChecks && !(getFalsyFlags(checkDeclarationInitializer(declaration, 0 /* Normal */)) & 32768 /* Undefined */) ? getNonUndefinedType(type) : type;
54521
54544
  }
54522
- return widenTypeInferredFromInitializer(declaration, getUnionType([getNonUndefinedType(type), checkDeclarationInitializer(declaration)], 2 /* Subtype */));
54545
+ return widenTypeInferredFromInitializer(declaration, getUnionType([getNonUndefinedType(type), checkDeclarationInitializer(declaration, 0 /* Normal */)], 2 /* Subtype */));
54523
54546
  }
54524
54547
  function getTypeForDeclarationFromJSDocComment(declaration) {
54525
54548
  var jsdocType = ts.getJSDocType(declaration);
@@ -54542,11 +54565,11 @@ var ts;
54542
54565
  return strictNullChecks && isOptional ? getOptionalType(type, isProperty) : type;
54543
54566
  }
54544
54567
  // Return the inferred type for a variable, parameter, or property declaration
54545
- function getTypeForVariableLikeDeclaration(declaration, includeOptionality) {
54568
+ function getTypeForVariableLikeDeclaration(declaration, includeOptionality, checkMode) {
54546
54569
  // A variable declared in a for..in statement is of type string, or of type keyof T when the
54547
54570
  // right hand expression is of a type parameter type.
54548
54571
  if (ts.isVariableDeclaration(declaration) && declaration.parent.parent.kind === 242 /* ForInStatement */) {
54549
- var indexType = getIndexType(getNonNullableTypeIfNeeded(checkExpression(declaration.parent.parent.expression)));
54572
+ var indexType = getIndexType(getNonNullableTypeIfNeeded(checkExpression(declaration.parent.parent.expression, /*checkMode*/ checkMode)));
54550
54573
  return indexType.flags & (262144 /* TypeParameter */ | 4194304 /* Index */) ? getExtractStringType(indexType) : stringType;
54551
54574
  }
54552
54575
  if (ts.isVariableDeclaration(declaration) && declaration.parent.parent.kind === 243 /* ForOfStatement */) {
@@ -54623,7 +54646,7 @@ var ts;
54623
54646
  return containerObjectType;
54624
54647
  }
54625
54648
  }
54626
- var type = widenTypeInferredFromInitializer(declaration, checkDeclarationInitializer(declaration));
54649
+ var type = widenTypeInferredFromInitializer(declaration, checkDeclarationInitializer(declaration, checkMode));
54627
54650
  return addOptionality(type, isProperty, isOptional);
54628
54651
  }
54629
54652
  if (ts.isPropertyDeclaration(declaration) && (noImplicitAny || ts.isInJSFile(declaration))) {
@@ -54995,7 +55018,7 @@ var ts;
54995
55018
  // contextual type or, if the element itself is a binding pattern, with the type implied by that binding
54996
55019
  // pattern.
54997
55020
  var contextualType = ts.isBindingPattern(element.name) ? getTypeFromBindingPattern(element.name, /*includePatternInType*/ true, /*reportErrors*/ false) : unknownType;
54998
- return addOptionality(widenTypeInferredFromInitializer(element, checkDeclarationInitializer(element, contextualType)));
55021
+ return addOptionality(widenTypeInferredFromInitializer(element, checkDeclarationInitializer(element, 0 /* Normal */, contextualType)));
54999
55022
  }
55000
55023
  if (ts.isBindingPattern(element.name)) {
55001
55024
  return getTypeFromBindingPattern(element.name, includePatternInType, reportErrors);
@@ -55084,7 +55107,7 @@ var ts;
55084
55107
  // binding pattern [x, s = ""]. Because the contextual type is a tuple type, the resulting type of [1, "one"] is the
55085
55108
  // tuple type [number, string]. Thus, the type inferred for 'x' is number and the type inferred for 's' is string.
55086
55109
  function getWidenedTypeForVariableLikeDeclaration(declaration, reportErrors) {
55087
- return widenTypeForVariableLikeDeclaration(getTypeForVariableLikeDeclaration(declaration, /*includeOptionality*/ true), declaration, reportErrors);
55110
+ return widenTypeForVariableLikeDeclaration(getTypeForVariableLikeDeclaration(declaration, /*includeOptionality*/ true, 0 /* Normal */), declaration, reportErrors);
55088
55111
  }
55089
55112
  function isGlobalSymbolConstructor(node) {
55090
55113
  var symbol = getSymbolOfNode(node);
@@ -55313,10 +55336,12 @@ var ts;
55313
55336
  if (writing === void 0) { writing = false; }
55314
55337
  var getter = ts.getDeclarationOfKind(symbol, 171 /* GetAccessor */);
55315
55338
  var setter = ts.getDeclarationOfKind(symbol, 172 /* SetAccessor */);
55316
- var setterType = getAnnotatedAccessorType(setter);
55317
55339
  // For write operations, prioritize type annotations on the setter
55318
- if (writing && setterType) {
55319
- return instantiateTypeIfNeeded(setterType, symbol);
55340
+ if (writing) {
55341
+ var setterType_1 = getAnnotatedAccessorType(setter);
55342
+ if (setterType_1) {
55343
+ return instantiateTypeIfNeeded(setterType_1, symbol);
55344
+ }
55320
55345
  }
55321
55346
  // Else defer to the getter type
55322
55347
  if (getter && ts.isInJSFile(getter)) {
@@ -55331,6 +55356,7 @@ var ts;
55331
55356
  return instantiateTypeIfNeeded(getterType, symbol);
55332
55357
  }
55333
55358
  // If the user didn't specify a return type, try to use the set-accessor's parameter type.
55359
+ var setterType = getAnnotatedAccessorType(setter);
55334
55360
  if (setterType) {
55335
55361
  return setterType;
55336
55362
  }
@@ -69888,12 +69914,16 @@ var ts;
69888
69914
  function isGenericTypeWithoutNullableConstraint(type) {
69889
69915
  return !!(type.flags & 465829888 /* Instantiable */ && !maybeTypeOfKind(getBaseConstraintOrType(type), 98304 /* Nullable */));
69890
69916
  }
69891
- function hasNonBindingPatternContextualTypeWithNoGenericTypes(node) {
69917
+ function hasContextualTypeWithNoGenericTypes(node, checkMode) {
69892
69918
  // Computing the contextual type for a child of a JSX element involves resolving the type of the
69893
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.
69894
69922
  var contextualType = (ts.isIdentifier(node) || ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node)) &&
69895
69923
  !((ts.isJsxOpeningElement(node.parent) || ts.isJsxSelfClosingElement(node.parent)) && node.parent.tagName === node) &&
69896
- getContextualType(node, 8 /* SkipBindingPatterns */);
69924
+ (checkMode && checkMode & 32 /* RestBindingElement */ ?
69925
+ getContextualType(node, 8 /* SkipBindingPatterns */)
69926
+ : getContextualType(node));
69897
69927
  return contextualType && !isGenericType(contextualType);
69898
69928
  }
69899
69929
  function getNarrowableTypeForReference(type, reference, checkMode) {
@@ -69906,7 +69936,7 @@ var ts;
69906
69936
  // 'string | undefined' to give control flow analysis the opportunity to narrow to type 'string'.
69907
69937
  var substituteConstraints = !(checkMode && checkMode & 2 /* Inferential */) &&
69908
69938
  someType(type, isGenericTypeWithUnionConstraint) &&
69909
- (isConstraintPosition(type, reference) || hasNonBindingPatternContextualTypeWithNoGenericTypes(reference));
69939
+ (isConstraintPosition(type, reference) || hasContextualTypeWithNoGenericTypes(reference, checkMode));
69910
69940
  return substituteConstraints ? mapType(type, function (t) { return t.flags & 465829888 /* Instantiable */ && !isMappedTypeGenericIndexedAccess(t) ? getBaseConstraintOrType(t) : t; }) : type;
69911
69941
  }
69912
69942
  function isExportOrExportExpression(location) {
@@ -69974,7 +70004,7 @@ var ts;
69974
70004
  var links = getNodeLinks(location);
69975
70005
  if (!(links.flags & 268435456 /* InCheckIdentifier */)) {
69976
70006
  links.flags |= 268435456 /* InCheckIdentifier */;
69977
- var parentType = getTypeForBindingElementParent(parent);
70007
+ var parentType = getTypeForBindingElementParent(parent, 0 /* Normal */);
69978
70008
  links.flags &= ~268435456 /* InCheckIdentifier */;
69979
70009
  if (parentType && parentType.flags & 1048576 /* Union */ && !(parent.kind === 163 /* Parameter */ && isSymbolAssigned(symbol))) {
69980
70010
  var pattern = declaration.parent;
@@ -70827,7 +70857,7 @@ var ts;
70827
70857
  var parent = declaration.parent.parent;
70828
70858
  var name = declaration.propertyName || declaration.name;
70829
70859
  var parentType = getContextualTypeForVariableLikeDeclaration(parent) ||
70830
- parent.kind !== 202 /* BindingElement */ && parent.initializer && checkDeclarationInitializer(parent);
70860
+ parent.kind !== 202 /* BindingElement */ && parent.initializer && checkDeclarationInitializer(parent, declaration.dotDotDotToken ? 32 /* RestBindingElement */ : 0 /* Normal */);
70831
70861
  if (!parentType || ts.isBindingPattern(name) || ts.isComputedNonLiteralName(name))
70832
70862
  return undefined;
70833
70863
  if (parent.name.kind === 201 /* ArrayBindingPattern */) {
@@ -75993,7 +76023,7 @@ var ts;
75993
76023
  var links = getSymbolLinks(parameter);
75994
76024
  if (!links.type) {
75995
76025
  var declaration = parameter.valueDeclaration;
75996
- links.type = type || getWidenedTypeForVariableLikeDeclaration(declaration, /*includeOptionality*/ true);
76026
+ links.type = type || getWidenedTypeForVariableLikeDeclaration(declaration, /*reportErrors*/ true);
75997
76027
  if (declaration.name.kind !== 79 /* Identifier */) {
75998
76028
  // if inference didn't come up with anything but unknown, fall back to the binding pattern if present.
75999
76029
  if (links.type === unknownType) {
@@ -77724,11 +77754,11 @@ var ts;
77724
77754
  }
77725
77755
  }
77726
77756
  function checkExpressionCached(node, checkMode) {
77757
+ if (checkMode && checkMode !== 0 /* Normal */) {
77758
+ return checkExpression(node, checkMode);
77759
+ }
77727
77760
  var links = getNodeLinks(node);
77728
77761
  if (!links.resolvedType) {
77729
- if (checkMode && checkMode !== 0 /* Normal */) {
77730
- return checkExpression(node, checkMode);
77731
- }
77732
77762
  // When computing a type that we're going to cache, we need to ignore any ongoing control flow
77733
77763
  // analysis because variables may have transient types in indeterminable states. Moving flowLoopStart
77734
77764
  // to the top of the stack ensures all transient types are computed from a known point.
@@ -77748,10 +77778,12 @@ var ts;
77748
77778
  node.kind === 228 /* AsExpression */ ||
77749
77779
  ts.isJSDocTypeAssertion(node);
77750
77780
  }
77751
- function checkDeclarationInitializer(declaration, contextualType) {
77781
+ function checkDeclarationInitializer(declaration, checkMode, contextualType) {
77752
77782
  var initializer = ts.getEffectiveInitializer(declaration);
77753
77783
  var type = getQuickTypeOfExpression(initializer) ||
77754
- (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));
77755
77787
  return ts.isParameter(declaration) && declaration.name.kind === 201 /* ArrayBindingPattern */ &&
77756
77788
  isTupleType(type) && !type.target.hasRestElement && getTypeReferenceArity(type) < declaration.name.elements.length ?
77757
77789
  padTupleType(type, declaration.name) : type;
@@ -80688,7 +80720,8 @@ var ts;
80688
80720
  }
80689
80721
  // check private/protected variable access
80690
80722
  var parent = node.parent.parent;
80691
- var parentType = getTypeForBindingElementParent(parent);
80723
+ var parentCheckMode = node.dotDotDotToken ? 32 /* RestBindingElement */ : 0 /* Normal */;
80724
+ var parentType = getTypeForBindingElementParent(parent, parentCheckMode);
80692
80725
  var name = node.propertyName || node.name;
80693
80726
  if (parentType && !ts.isBindingPattern(name)) {
80694
80727
  var exprType = getLiteralTypeFromPropertyName(name);
@@ -81927,7 +81960,7 @@ var ts;
81927
81960
  var declaration = catchClause.variableDeclaration;
81928
81961
  var typeNode = ts.getEffectiveTypeAnnotationNode(ts.getRootDeclaration(declaration));
81929
81962
  if (typeNode) {
81930
- var type = getTypeForVariableLikeDeclaration(declaration, /*includeOptionality*/ false);
81963
+ var type = getTypeForVariableLikeDeclaration(declaration, /*includeOptionality*/ false, 0 /* Normal */);
81931
81964
  if (type && !(type.flags & 3 /* AnyOrUnknown */)) {
81932
81965
  grammarErrorOnFirstToken(typeNode, ts.Diagnostics.Catch_clause_variable_type_annotation_must_be_any_or_unknown_if_specified);
81933
81966
  }
@@ -83033,7 +83066,7 @@ var ts;
83033
83066
  var isAmbientExternalModule = ts.isAmbientModule(node);
83034
83067
  var contextErrorMessage = isAmbientExternalModule
83035
83068
  ? 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;
83069
+ : ts.Diagnostics.A_namespace_declaration_is_only_allowed_at_the_top_level_of_a_namespace_or_module;
83037
83070
  if (checkGrammarModuleElementContext(node, contextErrorMessage)) {
83038
83071
  // If we hit a module declaration in an illegal context, just bail out to avoid cascading errors.
83039
83072
  return;
@@ -83349,7 +83382,7 @@ var ts;
83349
83382
  }
83350
83383
  }
83351
83384
  function checkImportDeclaration(node) {
83352
- 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)) {
83353
83386
  // If we hit an import declaration in an illegal context, just bail out to avoid cascading errors.
83354
83387
  return;
83355
83388
  }
@@ -83382,7 +83415,7 @@ var ts;
83382
83415
  checkAssertClause(node);
83383
83416
  }
83384
83417
  function checkImportEqualsDeclaration(node) {
83385
- 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)) {
83386
83419
  // If we hit an import declaration in an illegal context, just bail out to avoid cascading errors.
83387
83420
  return;
83388
83421
  }
@@ -83419,7 +83452,7 @@ var ts;
83419
83452
  }
83420
83453
  }
83421
83454
  function checkExportDeclaration(node) {
83422
- 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)) {
83423
83456
  // If we hit an export in an illegal context, just bail out to avoid cascading errors.
83424
83457
  return;
83425
83458
  }
@@ -84653,7 +84686,7 @@ var ts;
84653
84686
  return errorType;
84654
84687
  }
84655
84688
  if (ts.isBindingPattern(node)) {
84656
- return getTypeForVariableLikeDeclaration(node.parent, /*includeOptionality*/ true) || errorType;
84689
+ return getTypeForVariableLikeDeclaration(node.parent, /*includeOptionality*/ true, 0 /* Normal */) || errorType;
84657
84690
  }
84658
84691
  if (isInRightSideOfImportOrExportAssignment(node)) {
84659
84692
  var symbol = getSymbolAtLocation(node);
@@ -114400,9 +114433,9 @@ var ts;
114400
114433
  ts.Diagnostics.A_return_statement_cannot_be_used_inside_a_class_static_block.code,
114401
114434
  ts.Diagnostics.A_set_accessor_cannot_have_rest_parameter.code,
114402
114435
  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,
114436
+ ts.Diagnostics.An_export_declaration_can_only_be_used_at_the_top_level_of_a_module.code,
114404
114437
  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,
114438
+ ts.Diagnostics.An_import_declaration_can_only_be_used_at_the_top_level_of_a_module.code,
114406
114439
  ts.Diagnostics.An_import_declaration_cannot_have_modifiers.code,
114407
114440
  ts.Diagnostics.An_object_member_cannot_be_declared_optional.code,
114408
114441
  ts.Diagnostics.Argument_of_dynamic_import_cannot_be_spread_element.code,
@@ -115470,7 +115503,7 @@ var ts;
115470
115503
  ts.Debug.assert(!!sourceFile.bindDiagnostics);
115471
115504
  var isJs = sourceFile.scriptKind === 1 /* JS */ || sourceFile.scriptKind === 2 /* JSX */;
115472
115505
  var isCheckJs = isJs && ts.isCheckJsEnabledForFile(sourceFile, options);
115473
- var isPlainJs = isJs && !sourceFile.checkJsDirective && options.checkJs === undefined;
115506
+ var isPlainJs = ts.isPlainJsFile(sourceFile, options.checkJs);
115474
115507
  var isTsNoCheck = !!sourceFile.checkJsDirective && sourceFile.checkJsDirective.enabled === false;
115475
115508
  // By default, only type-check .ts, .tsx, Deferred, plain JS, checked JS and External
115476
115509
  // - plain JS: .js files with no // ts-check and checkJs: undefined
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.20220209",
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": [