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.
@@ -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.20220209";
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),
@@ -14330,6 +14332,10 @@ var ts;
14330
14332
  return getSourceFileOfNode(module.valueDeclaration || getNonAugmentationDeclaration(module));
14331
14333
  }
14332
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;
14333
14339
  function isStatementWithLocals(node) {
14334
14340
  switch (node.kind) {
14335
14341
  case 234 /* Block */:
@@ -47107,6 +47113,9 @@ var ts;
47107
47113
  CheckMode[CheckMode["SkipContextSensitive"] = 4] = "SkipContextSensitive";
47108
47114
  CheckMode[CheckMode["SkipGenericFunctions"] = 8] = "SkipGenericFunctions";
47109
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
47110
47119
  })(CheckMode || (CheckMode = {}));
47111
47120
  var SignatureCheckMode;
47112
47121
  (function (SignatureCheckMode) {
@@ -48159,13 +48168,13 @@ var ts;
48159
48168
  else { // error
48160
48169
  var isEitherEnum = !!(target.flags & 384 /* Enum */ || source.flags & 384 /* Enum */);
48161
48170
  var isEitherBlockScoped_1 = !!(target.flags & 2 /* BlockScopedVariable */ || source.flags & 2 /* BlockScopedVariable */);
48162
- var message = isEitherEnum
48163
- ? ts.Diagnostics.Enum_declarations_can_only_merge_with_namespace_or_other_enum_declarations
48164
- : isEitherBlockScoped_1
48165
- ? 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
48166
48173
  : ts.Diagnostics.Duplicate_identifier_0;
48167
48174
  var sourceSymbolFile = source.declarations && ts.getSourceFileOfNode(source.declarations[0]);
48168
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);
48169
48178
  var symbolName_1 = symbolToString(source);
48170
48179
  // Collect top-level duplicate identifier errors into one mapping, so we can then merge their diagnostics if there are a bunch
48171
48180
  if (sourceSymbolFile && targetSymbolFile && amalgamatedDuplicates && !isEitherEnum && sourceSymbolFile !== targetSymbolFile) {
@@ -48177,12 +48186,16 @@ var ts;
48177
48186
  var conflictingSymbolInfo = ts.getOrUpdate(filesDuplicates.conflictingSymbols, symbolName_1, function () {
48178
48187
  return ({ isBlockScoped: isEitherBlockScoped_1, firstFileLocations: [], secondFileLocations: [] });
48179
48188
  });
48180
- addDuplicateLocations(conflictingSymbolInfo.firstFileLocations, source);
48181
- addDuplicateLocations(conflictingSymbolInfo.secondFileLocations, target);
48189
+ if (!isSourcePlainJs)
48190
+ addDuplicateLocations(conflictingSymbolInfo.firstFileLocations, source);
48191
+ if (!isTargetPlainJs)
48192
+ addDuplicateLocations(conflictingSymbolInfo.secondFileLocations, target);
48182
48193
  }
48183
48194
  else {
48184
- addDuplicateDeclarationErrorsForSymbols(source, message, symbolName_1, target);
48185
- 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);
48186
48199
  }
48187
48200
  }
48188
48201
  return target;
@@ -48639,6 +48652,8 @@ var ts;
48639
48652
  // type parameters are visible in parameter list, return type and type parameter list
48640
48653
  ? lastLocation === location.type ||
48641
48654
  lastLocation.kind === 163 /* Parameter */ ||
48655
+ lastLocation.kind === 338 /* JSDocParameterTag */ ||
48656
+ lastLocation.kind === 339 /* JSDocReturnTag */ ||
48642
48657
  lastLocation.kind === 162 /* TypeParameter */
48643
48658
  // local types not visible outside the function body
48644
48659
  : false;
@@ -48898,9 +48913,9 @@ var ts;
48898
48913
  lastSelfReferenceLocation = location;
48899
48914
  }
48900
48915
  lastLocation = location;
48901
- location = ts.isJSDocTemplateTag(location) ?
48902
- ts.getEffectiveContainerForJSDocTemplateTag(location) || location.parent :
48903
- 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;
48904
48919
  }
48905
48920
  // We just climbed up parents looking for the name, meaning that we started in a descendant node of `lastLocation`.
48906
48921
  // If `result === lastSelfReferenceLocation.symbol`, that means that we are somewhere inside `lastSelfReferenceLocation` looking up a name, and resolving to `lastLocation` itself.
@@ -50034,16 +50049,20 @@ var ts;
50034
50049
  return;
50035
50050
  }
50036
50051
  var host = ts.getJSDocHost(node);
50037
- if (host &&
50038
- ts.isExpressionStatement(host) &&
50039
- ts.isBinaryExpression(host.expression) &&
50040
- ts.getAssignmentDeclarationKind(host.expression) === 3 /* PrototypeProperty */) {
50041
- // 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
50042
50054
  var symbol = getSymbolOfNode(host.expression.left);
50043
50055
  if (symbol) {
50044
50056
  return getDeclarationOfJSPrototypeContainer(symbol);
50045
50057
  }
50046
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
+ }
50047
50066
  if (host && (ts.isObjectLiteralMethod(host) || ts.isPropertyAssignment(host)) &&
50048
50067
  ts.isBinaryExpression(host.parent.parent) &&
50049
50068
  ts.getAssignmentDeclarationKind(host.parent.parent) === 6 /* Prototype */) {
@@ -54530,9 +54549,12 @@ var ts;
54530
54549
  }
54531
54550
  // Return the type of a binding element parent. We check SymbolLinks first to see if a type has been
54532
54551
  // assigned by contextual typing.
54533
- function getTypeForBindingElementParent(node) {
54552
+ function getTypeForBindingElementParent(node, checkMode) {
54553
+ if (checkMode !== 0 /* Normal */) {
54554
+ return getTypeForVariableLikeDeclaration(node, /*includeOptionality*/ false, checkMode);
54555
+ }
54534
54556
  var symbol = getSymbolOfNode(node);
54535
- return symbol && getSymbolLinks(symbol).type || getTypeForVariableLikeDeclaration(node, /*includeOptionality*/ false);
54557
+ return symbol && getSymbolLinks(symbol).type || getTypeForVariableLikeDeclaration(node, /*includeOptionality*/ false, checkMode);
54536
54558
  }
54537
54559
  function getRestType(source, properties, symbol) {
54538
54560
  source = filterType(source, function (t) { return !(t.flags & 98304 /* Nullable */); });
@@ -54650,7 +54672,8 @@ var ts;
54650
54672
  }
54651
54673
  /** Return the inferred type for a binding element */
54652
54674
  function getTypeForBindingElement(declaration) {
54653
- var parentType = getTypeForBindingElementParent(declaration.parent.parent);
54675
+ var checkMode = declaration.dotDotDotToken ? 32 /* RestBindingElement */ : 0 /* Normal */;
54676
+ var parentType = getTypeForBindingElementParent(declaration.parent.parent, checkMode);
54654
54677
  return parentType && getBindingElementTypeFromParentType(declaration, parentType);
54655
54678
  }
54656
54679
  function getBindingElementTypeFromParentType(declaration, parentType) {
@@ -54722,9 +54745,9 @@ var ts;
54722
54745
  if (ts.getEffectiveTypeAnnotationNode(ts.walkUpBindingElementsAndPatterns(declaration))) {
54723
54746
  // In strict null checking mode, if a default value of a non-undefined type is specified, remove
54724
54747
  // undefined from the final type.
54725
- return strictNullChecks && !(getFalsyFlags(checkDeclarationInitializer(declaration)) & 32768 /* Undefined */) ? getNonUndefinedType(type) : type;
54748
+ return strictNullChecks && !(getFalsyFlags(checkDeclarationInitializer(declaration, 0 /* Normal */)) & 32768 /* Undefined */) ? getNonUndefinedType(type) : type;
54726
54749
  }
54727
- return widenTypeInferredFromInitializer(declaration, getUnionType([getNonUndefinedType(type), checkDeclarationInitializer(declaration)], 2 /* Subtype */));
54750
+ return widenTypeInferredFromInitializer(declaration, getUnionType([getNonUndefinedType(type), checkDeclarationInitializer(declaration, 0 /* Normal */)], 2 /* Subtype */));
54728
54751
  }
54729
54752
  function getTypeForDeclarationFromJSDocComment(declaration) {
54730
54753
  var jsdocType = ts.getJSDocType(declaration);
@@ -54747,11 +54770,11 @@ var ts;
54747
54770
  return strictNullChecks && isOptional ? getOptionalType(type, isProperty) : type;
54748
54771
  }
54749
54772
  // Return the inferred type for a variable, parameter, or property declaration
54750
- function getTypeForVariableLikeDeclaration(declaration, includeOptionality) {
54773
+ function getTypeForVariableLikeDeclaration(declaration, includeOptionality, checkMode) {
54751
54774
  // A variable declared in a for..in statement is of type string, or of type keyof T when the
54752
54775
  // right hand expression is of a type parameter type.
54753
54776
  if (ts.isVariableDeclaration(declaration) && declaration.parent.parent.kind === 242 /* ForInStatement */) {
54754
- var indexType = getIndexType(getNonNullableTypeIfNeeded(checkExpression(declaration.parent.parent.expression)));
54777
+ var indexType = getIndexType(getNonNullableTypeIfNeeded(checkExpression(declaration.parent.parent.expression, /*checkMode*/ checkMode)));
54755
54778
  return indexType.flags & (262144 /* TypeParameter */ | 4194304 /* Index */) ? getExtractStringType(indexType) : stringType;
54756
54779
  }
54757
54780
  if (ts.isVariableDeclaration(declaration) && declaration.parent.parent.kind === 243 /* ForOfStatement */) {
@@ -54828,7 +54851,7 @@ var ts;
54828
54851
  return containerObjectType;
54829
54852
  }
54830
54853
  }
54831
- var type = widenTypeInferredFromInitializer(declaration, checkDeclarationInitializer(declaration));
54854
+ var type = widenTypeInferredFromInitializer(declaration, checkDeclarationInitializer(declaration, checkMode));
54832
54855
  return addOptionality(type, isProperty, isOptional);
54833
54856
  }
54834
54857
  if (ts.isPropertyDeclaration(declaration) && (noImplicitAny || ts.isInJSFile(declaration))) {
@@ -55200,7 +55223,7 @@ var ts;
55200
55223
  // contextual type or, if the element itself is a binding pattern, with the type implied by that binding
55201
55224
  // pattern.
55202
55225
  var contextualType = ts.isBindingPattern(element.name) ? getTypeFromBindingPattern(element.name, /*includePatternInType*/ true, /*reportErrors*/ false) : unknownType;
55203
- return addOptionality(widenTypeInferredFromInitializer(element, checkDeclarationInitializer(element, contextualType)));
55226
+ return addOptionality(widenTypeInferredFromInitializer(element, checkDeclarationInitializer(element, 0 /* Normal */, contextualType)));
55204
55227
  }
55205
55228
  if (ts.isBindingPattern(element.name)) {
55206
55229
  return getTypeFromBindingPattern(element.name, includePatternInType, reportErrors);
@@ -55289,7 +55312,7 @@ var ts;
55289
55312
  // binding pattern [x, s = ""]. Because the contextual type is a tuple type, the resulting type of [1, "one"] is the
55290
55313
  // tuple type [number, string]. Thus, the type inferred for 'x' is number and the type inferred for 's' is string.
55291
55314
  function getWidenedTypeForVariableLikeDeclaration(declaration, reportErrors) {
55292
- return widenTypeForVariableLikeDeclaration(getTypeForVariableLikeDeclaration(declaration, /*includeOptionality*/ true), declaration, reportErrors);
55315
+ return widenTypeForVariableLikeDeclaration(getTypeForVariableLikeDeclaration(declaration, /*includeOptionality*/ true, 0 /* Normal */), declaration, reportErrors);
55293
55316
  }
55294
55317
  function isGlobalSymbolConstructor(node) {
55295
55318
  var symbol = getSymbolOfNode(node);
@@ -55518,10 +55541,12 @@ var ts;
55518
55541
  if (writing === void 0) { writing = false; }
55519
55542
  var getter = ts.getDeclarationOfKind(symbol, 171 /* GetAccessor */);
55520
55543
  var setter = ts.getDeclarationOfKind(symbol, 172 /* SetAccessor */);
55521
- var setterType = getAnnotatedAccessorType(setter);
55522
55544
  // For write operations, prioritize type annotations on the setter
55523
- if (writing && setterType) {
55524
- return instantiateTypeIfNeeded(setterType, symbol);
55545
+ if (writing) {
55546
+ var setterType_1 = getAnnotatedAccessorType(setter);
55547
+ if (setterType_1) {
55548
+ return instantiateTypeIfNeeded(setterType_1, symbol);
55549
+ }
55525
55550
  }
55526
55551
  // Else defer to the getter type
55527
55552
  if (getter && ts.isInJSFile(getter)) {
@@ -55536,6 +55561,7 @@ var ts;
55536
55561
  return instantiateTypeIfNeeded(getterType, symbol);
55537
55562
  }
55538
55563
  // If the user didn't specify a return type, try to use the set-accessor's parameter type.
55564
+ var setterType = getAnnotatedAccessorType(setter);
55539
55565
  if (setterType) {
55540
55566
  return setterType;
55541
55567
  }
@@ -70093,12 +70119,16 @@ var ts;
70093
70119
  function isGenericTypeWithoutNullableConstraint(type) {
70094
70120
  return !!(type.flags & 465829888 /* Instantiable */ && !maybeTypeOfKind(getBaseConstraintOrType(type), 98304 /* Nullable */));
70095
70121
  }
70096
- function hasNonBindingPatternContextualTypeWithNoGenericTypes(node) {
70122
+ function hasContextualTypeWithNoGenericTypes(node, checkMode) {
70097
70123
  // Computing the contextual type for a child of a JSX element involves resolving the type of the
70098
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.
70099
70127
  var contextualType = (ts.isIdentifier(node) || ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node)) &&
70100
70128
  !((ts.isJsxOpeningElement(node.parent) || ts.isJsxSelfClosingElement(node.parent)) && node.parent.tagName === node) &&
70101
- getContextualType(node, 8 /* SkipBindingPatterns */);
70129
+ (checkMode && checkMode & 32 /* RestBindingElement */ ?
70130
+ getContextualType(node, 8 /* SkipBindingPatterns */)
70131
+ : getContextualType(node));
70102
70132
  return contextualType && !isGenericType(contextualType);
70103
70133
  }
70104
70134
  function getNarrowableTypeForReference(type, reference, checkMode) {
@@ -70111,7 +70141,7 @@ var ts;
70111
70141
  // 'string | undefined' to give control flow analysis the opportunity to narrow to type 'string'.
70112
70142
  var substituteConstraints = !(checkMode && checkMode & 2 /* Inferential */) &&
70113
70143
  someType(type, isGenericTypeWithUnionConstraint) &&
70114
- (isConstraintPosition(type, reference) || hasNonBindingPatternContextualTypeWithNoGenericTypes(reference));
70144
+ (isConstraintPosition(type, reference) || hasContextualTypeWithNoGenericTypes(reference, checkMode));
70115
70145
  return substituteConstraints ? mapType(type, function (t) { return t.flags & 465829888 /* Instantiable */ && !isMappedTypeGenericIndexedAccess(t) ? getBaseConstraintOrType(t) : t; }) : type;
70116
70146
  }
70117
70147
  function isExportOrExportExpression(location) {
@@ -70179,7 +70209,7 @@ var ts;
70179
70209
  var links = getNodeLinks(location);
70180
70210
  if (!(links.flags & 268435456 /* InCheckIdentifier */)) {
70181
70211
  links.flags |= 268435456 /* InCheckIdentifier */;
70182
- var parentType = getTypeForBindingElementParent(parent);
70212
+ var parentType = getTypeForBindingElementParent(parent, 0 /* Normal */);
70183
70213
  links.flags &= ~268435456 /* InCheckIdentifier */;
70184
70214
  if (parentType && parentType.flags & 1048576 /* Union */ && !(parent.kind === 163 /* Parameter */ && isSymbolAssigned(symbol))) {
70185
70215
  var pattern = declaration.parent;
@@ -71032,7 +71062,7 @@ var ts;
71032
71062
  var parent = declaration.parent.parent;
71033
71063
  var name = declaration.propertyName || declaration.name;
71034
71064
  var parentType = getContextualTypeForVariableLikeDeclaration(parent) ||
71035
- parent.kind !== 202 /* BindingElement */ && parent.initializer && checkDeclarationInitializer(parent);
71065
+ parent.kind !== 202 /* BindingElement */ && parent.initializer && checkDeclarationInitializer(parent, declaration.dotDotDotToken ? 32 /* RestBindingElement */ : 0 /* Normal */);
71036
71066
  if (!parentType || ts.isBindingPattern(name) || ts.isComputedNonLiteralName(name))
71037
71067
  return undefined;
71038
71068
  if (parent.name.kind === 201 /* ArrayBindingPattern */) {
@@ -76198,7 +76228,7 @@ var ts;
76198
76228
  var links = getSymbolLinks(parameter);
76199
76229
  if (!links.type) {
76200
76230
  var declaration = parameter.valueDeclaration;
76201
- links.type = type || getWidenedTypeForVariableLikeDeclaration(declaration, /*includeOptionality*/ true);
76231
+ links.type = type || getWidenedTypeForVariableLikeDeclaration(declaration, /*reportErrors*/ true);
76202
76232
  if (declaration.name.kind !== 79 /* Identifier */) {
76203
76233
  // if inference didn't come up with anything but unknown, fall back to the binding pattern if present.
76204
76234
  if (links.type === unknownType) {
@@ -77929,11 +77959,11 @@ var ts;
77929
77959
  }
77930
77960
  }
77931
77961
  function checkExpressionCached(node, checkMode) {
77962
+ if (checkMode && checkMode !== 0 /* Normal */) {
77963
+ return checkExpression(node, checkMode);
77964
+ }
77932
77965
  var links = getNodeLinks(node);
77933
77966
  if (!links.resolvedType) {
77934
- if (checkMode && checkMode !== 0 /* Normal */) {
77935
- return checkExpression(node, checkMode);
77936
- }
77937
77967
  // When computing a type that we're going to cache, we need to ignore any ongoing control flow
77938
77968
  // analysis because variables may have transient types in indeterminable states. Moving flowLoopStart
77939
77969
  // to the top of the stack ensures all transient types are computed from a known point.
@@ -77953,10 +77983,12 @@ var ts;
77953
77983
  node.kind === 228 /* AsExpression */ ||
77954
77984
  ts.isJSDocTypeAssertion(node);
77955
77985
  }
77956
- function checkDeclarationInitializer(declaration, contextualType) {
77986
+ function checkDeclarationInitializer(declaration, checkMode, contextualType) {
77957
77987
  var initializer = ts.getEffectiveInitializer(declaration);
77958
77988
  var type = getQuickTypeOfExpression(initializer) ||
77959
- (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));
77960
77992
  return ts.isParameter(declaration) && declaration.name.kind === 201 /* ArrayBindingPattern */ &&
77961
77993
  isTupleType(type) && !type.target.hasRestElement && getTypeReferenceArity(type) < declaration.name.elements.length ?
77962
77994
  padTupleType(type, declaration.name) : type;
@@ -80893,7 +80925,8 @@ var ts;
80893
80925
  }
80894
80926
  // check private/protected variable access
80895
80927
  var parent = node.parent.parent;
80896
- var parentType = getTypeForBindingElementParent(parent);
80928
+ var parentCheckMode = node.dotDotDotToken ? 32 /* RestBindingElement */ : 0 /* Normal */;
80929
+ var parentType = getTypeForBindingElementParent(parent, parentCheckMode);
80897
80930
  var name = node.propertyName || node.name;
80898
80931
  if (parentType && !ts.isBindingPattern(name)) {
80899
80932
  var exprType = getLiteralTypeFromPropertyName(name);
@@ -82132,7 +82165,7 @@ var ts;
82132
82165
  var declaration = catchClause.variableDeclaration;
82133
82166
  var typeNode = ts.getEffectiveTypeAnnotationNode(ts.getRootDeclaration(declaration));
82134
82167
  if (typeNode) {
82135
- var type = getTypeForVariableLikeDeclaration(declaration, /*includeOptionality*/ false);
82168
+ var type = getTypeForVariableLikeDeclaration(declaration, /*includeOptionality*/ false, 0 /* Normal */);
82136
82169
  if (type && !(type.flags & 3 /* AnyOrUnknown */)) {
82137
82170
  grammarErrorOnFirstToken(typeNode, ts.Diagnostics.Catch_clause_variable_type_annotation_must_be_any_or_unknown_if_specified);
82138
82171
  }
@@ -83238,7 +83271,7 @@ var ts;
83238
83271
  var isAmbientExternalModule = ts.isAmbientModule(node);
83239
83272
  var contextErrorMessage = isAmbientExternalModule
83240
83273
  ? ts.Diagnostics.An_ambient_module_declaration_is_only_allowed_at_the_top_level_in_a_file
83241
- : 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;
83242
83275
  if (checkGrammarModuleElementContext(node, contextErrorMessage)) {
83243
83276
  // If we hit a module declaration in an illegal context, just bail out to avoid cascading errors.
83244
83277
  return;
@@ -83554,7 +83587,7 @@ var ts;
83554
83587
  }
83555
83588
  }
83556
83589
  function checkImportDeclaration(node) {
83557
- 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)) {
83558
83591
  // If we hit an import declaration in an illegal context, just bail out to avoid cascading errors.
83559
83592
  return;
83560
83593
  }
@@ -83587,7 +83620,7 @@ var ts;
83587
83620
  checkAssertClause(node);
83588
83621
  }
83589
83622
  function checkImportEqualsDeclaration(node) {
83590
- 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)) {
83591
83624
  // If we hit an import declaration in an illegal context, just bail out to avoid cascading errors.
83592
83625
  return;
83593
83626
  }
@@ -83624,7 +83657,7 @@ var ts;
83624
83657
  }
83625
83658
  }
83626
83659
  function checkExportDeclaration(node) {
83627
- 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)) {
83628
83661
  // If we hit an export in an illegal context, just bail out to avoid cascading errors.
83629
83662
  return;
83630
83663
  }
@@ -84858,7 +84891,7 @@ var ts;
84858
84891
  return errorType;
84859
84892
  }
84860
84893
  if (ts.isBindingPattern(node)) {
84861
- return getTypeForVariableLikeDeclaration(node.parent, /*includeOptionality*/ true) || errorType;
84894
+ return getTypeForVariableLikeDeclaration(node.parent, /*includeOptionality*/ true, 0 /* Normal */) || errorType;
84862
84895
  }
84863
84896
  if (isInRightSideOfImportOrExportAssignment(node)) {
84864
84897
  var symbol = getSymbolAtLocation(node);
@@ -114605,9 +114638,9 @@ var ts;
114605
114638
  ts.Diagnostics.A_return_statement_cannot_be_used_inside_a_class_static_block.code,
114606
114639
  ts.Diagnostics.A_set_accessor_cannot_have_rest_parameter.code,
114607
114640
  ts.Diagnostics.A_set_accessor_must_have_exactly_one_parameter.code,
114608
- 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,
114609
114642
  ts.Diagnostics.An_export_declaration_cannot_have_modifiers.code,
114610
- 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,
114611
114644
  ts.Diagnostics.An_import_declaration_cannot_have_modifiers.code,
114612
114645
  ts.Diagnostics.An_object_member_cannot_be_declared_optional.code,
114613
114646
  ts.Diagnostics.Argument_of_dynamic_import_cannot_be_spread_element.code,
@@ -115675,7 +115708,7 @@ var ts;
115675
115708
  ts.Debug.assert(!!sourceFile.bindDiagnostics);
115676
115709
  var isJs = sourceFile.scriptKind === 1 /* JS */ || sourceFile.scriptKind === 2 /* JSX */;
115677
115710
  var isCheckJs = isJs && ts.isCheckJsEnabledForFile(sourceFile, options);
115678
- var isPlainJs = isJs && !sourceFile.checkJsDirective && options.checkJs === undefined;
115711
+ var isPlainJs = ts.isPlainJsFile(sourceFile, options.checkJs);
115679
115712
  var isTsNoCheck = !!sourceFile.checkJsDirective && sourceFile.checkJsDirective.enabled === false;
115680
115713
  // By default, only type-check .ts, .tsx, Deferred, plain JS, checked JS and External
115681
115714
  // - plain JS: .js files with no // ts-check and checkJs: undefined