@typescript-deploys/pr-build 5.3.0-pr-55860-30 → 5.3.0-pr-55867-7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/tsc.js CHANGED
@@ -18,7 +18,7 @@ and limitations under the License.
18
18
 
19
19
  // src/compiler/corePublic.ts
20
20
  var versionMajorMinor = "5.3";
21
- var version = `${versionMajorMinor}.0-insiders.20230928`;
21
+ var version = `${versionMajorMinor}.0-insiders.20230929`;
22
22
 
23
23
  // src/compiler/core.ts
24
24
  var emptyArray = [];
@@ -6202,7 +6202,7 @@ var Diagnostics = {
6202
6202
  An_arithmetic_operand_must_be_of_type_any_number_bigint_or_an_enum_type: diag(2356, 1 /* Error */, "An_arithmetic_operand_must_be_of_type_any_number_bigint_or_an_enum_type_2356", "An arithmetic operand must be of type 'any', 'number', 'bigint' or an enum type."),
6203
6203
  The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_or_a_property_access: diag(2357, 1 /* Error */, "The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_or_a_property_access_2357", "The operand of an increment or decrement operator must be a variable or a property access."),
6204
6204
  The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter: diag(2358, 1 /* Error */, "The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_paramete_2358", "The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter."),
6205
- The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type: diag(2359, 1 /* Error */, "The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_F_2359", "The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type."),
6205
+ The_right_hand_side_of_an_instanceof_expression_must_be_either_of_type_any_a_class_function_or_other_type_assignable_to_the_Function_interface_type_or_an_object_type_with_a_Symbol_hasInstance_method: diag(2359, 1 /* Error */, "The_right_hand_side_of_an_instanceof_expression_must_be_either_of_type_any_a_class_function_or_other_2359", "The right-hand side of an 'instanceof' expression must be either of type 'any', a class, function, or other type assignable to the 'Function' interface type, or an object type with a 'Symbol.hasInstance' method."),
6206
6206
  The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type: diag(2362, 1 /* Error */, "The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type_2362", "The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type."),
6207
6207
  The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type: diag(2363, 1 /* Error */, "The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type_2363", "The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type."),
6208
6208
  The_left_hand_side_of_an_assignment_expression_must_be_a_variable_or_a_property_access: diag(2364, 1 /* Error */, "The_left_hand_side_of_an_assignment_expression_must_be_a_variable_or_a_property_access_2364", "The left-hand side of an assignment expression must be a variable or a property access."),
@@ -6651,7 +6651,8 @@ var Diagnostics = {
6651
6651
  Import_attributes_cannot_be_used_with_type_only_imports_or_exports: diag(2857, 1 /* Error */, "Import_attributes_cannot_be_used_with_type_only_imports_or_exports_2857", "Import attributes cannot be used with type-only imports or exports."),
6652
6652
  Import_attribute_values_must_be_string_literal_expressions: diag(2858, 1 /* Error */, "Import_attribute_values_must_be_string_literal_expressions_2858", "Import attribute values must be string literal expressions."),
6653
6653
  Excessive_complexity_comparing_types_0_and_1: diag(2859, 1 /* Error */, "Excessive_complexity_comparing_types_0_and_1_2859", "Excessive complexity comparing types '{0}' and '{1}'."),
6654
- The_type_of_this_declaration_is_ambiguous_and_may_be_observed_as_either_0_or_1: diag(2860, 1 /* Error */, "The_type_of_this_declaration_is_ambiguous_and_may_be_observed_as_either_0_or_1_2860", "The type of this declaration is ambiguous and may be observed as either '{0}' or '{1}'."),
6654
+ The_left_hand_side_of_an_instanceof_expression_must_be_assignable_to_the_first_argument_of_the_right_hand_side_s_Symbol_hasInstance_method: diag(2860, 1 /* Error */, "The_left_hand_side_of_an_instanceof_expression_must_be_assignable_to_the_first_argument_of_the_right_2860", "The left-hand side of an 'instanceof' expression must be assignable to the first argument of the right-hand side's '[Symbol.hasInstance]' method."),
6655
+ An_object_s_Symbol_hasInstance_method_must_return_a_boolean_value_for_it_to_be_used_on_the_right_hand_side_of_an_instanceof_expression: diag(2861, 1 /* Error */, "An_object_s_Symbol_hasInstance_method_must_return_a_boolean_value_for_it_to_be_used_on_the_right_han_2861", "An object's '[Symbol.hasInstance]' method must return a boolean value for it to be used on the right-hand side of an 'instanceof' expression."),
6655
6656
  Import_declaration_0_is_using_private_name_1: diag(4e3, 1 /* Error */, "Import_declaration_0_is_using_private_name_1_4000", "Import declaration '{0}' is using private name '{1}'."),
6656
6657
  Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: diag(4002, 1 /* Error */, "Type_parameter_0_of_exported_class_has_or_is_using_private_name_1_4002", "Type parameter '{0}' of exported class has or is using private name '{1}'."),
6657
6658
  Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: diag(4004, 1 /* Error */, "Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1_4004", "Type parameter '{0}' of exported interface has or is using private name '{1}'."),
@@ -10815,6 +10816,13 @@ function isAutoAccessorPropertyDeclaration(node) {
10815
10816
  return isPropertyDeclaration(node) && hasAccessorModifier(node);
10816
10817
  }
10817
10818
  function isClassFieldAndNotAutoAccessor(node) {
10819
+ if (isInJSFile(node) && isExpandoPropertyDeclaration(node)) {
10820
+ return (!isBindableStaticAccessExpression(node) || !isPrototypeAccess(node.expression)) && !isBindableStaticNameExpression(
10821
+ node,
10822
+ /*excludeThisKeyword*/
10823
+ true
10824
+ );
10825
+ }
10818
10826
  return node.parent && isClassLike(node.parent) && isPropertyDeclaration(node) && !hasAccessorModifier(node);
10819
10827
  }
10820
10828
  function isMethodOrAccessor(node) {
@@ -13077,6 +13085,8 @@ function getInvokedExpression(node) {
13077
13085
  case 286 /* JsxOpeningElement */:
13078
13086
  case 285 /* JsxSelfClosingElement */:
13079
13087
  return node.tagName;
13088
+ case 226 /* BinaryExpression */:
13089
+ return node.right;
13080
13090
  default:
13081
13091
  return node.expression;
13082
13092
  }
@@ -15583,6 +15593,12 @@ function isRightSideOfAccessExpression(node) {
15583
15593
  function isRightSideOfQualifiedNameOrPropertyAccessOrJSDocMemberName(node) {
15584
15594
  return isQualifiedName(node.parent) && node.parent.right === node || isPropertyAccessExpression(node.parent) && node.parent.name === node || isJSDocMemberName(node.parent) && node.parent.right === node;
15585
15595
  }
15596
+ function isInstanceOfExpression(node) {
15597
+ return isBinaryExpression(node) && node.operatorToken.kind === 104 /* InstanceOfKeyword */;
15598
+ }
15599
+ function isRightSideOfInstanceofExpression(node) {
15600
+ return isInstanceOfExpression(node.parent) && node === node.parent.right;
15601
+ }
15586
15602
  function isEmptyObjectLiteral(expression) {
15587
15603
  return expression.kind === 210 /* ObjectLiteralExpression */ && expression.properties.length === 0;
15588
15604
  }
@@ -43070,9 +43086,8 @@ var CheckMode = /* @__PURE__ */ ((CheckMode3) => {
43070
43086
  CheckMode3[CheckMode3["SkipContextSensitive"] = 4] = "SkipContextSensitive";
43071
43087
  CheckMode3[CheckMode3["SkipGenericFunctions"] = 8] = "SkipGenericFunctions";
43072
43088
  CheckMode3[CheckMode3["IsForSignatureHelp"] = 16] = "IsForSignatureHelp";
43073
- CheckMode3[CheckMode3["IsForStringLiteralArgumentCompletions"] = 32] = "IsForStringLiteralArgumentCompletions";
43074
- CheckMode3[CheckMode3["RestBindingElement"] = 64] = "RestBindingElement";
43075
- CheckMode3[CheckMode3["TypeOnly"] = 128] = "TypeOnly";
43089
+ CheckMode3[CheckMode3["RestBindingElement"] = 32] = "RestBindingElement";
43090
+ CheckMode3[CheckMode3["TypeOnly"] = 64] = "TypeOnly";
43076
43091
  return CheckMode3;
43077
43092
  })(CheckMode || {});
43078
43093
  var SignatureCheckMode = /* @__PURE__ */ ((SignatureCheckMode3) => {
@@ -43559,7 +43574,7 @@ function createTypeChecker(host) {
43559
43574
  candidates,
43560
43575
  /*argumentCount*/
43561
43576
  void 0,
43562
- 32 /* IsForStringLiteralArgumentCompletions */
43577
+ 0 /* Normal */
43563
43578
  ));
43564
43579
  for (const candidate of candidates) {
43565
43580
  candidatesSet.add(candidate);
@@ -44069,7 +44084,6 @@ function createTypeChecker(host) {
44069
44084
  var potentialReflectCollisions = [];
44070
44085
  var potentialUnusedRenamedBindingElementsInTypes = [];
44071
44086
  var awaitedTypeStack = [];
44072
- var ambiguousVariableDeclarationsWhenWidened = [];
44073
44087
  var diagnostics = createDiagnosticCollection();
44074
44088
  var suggestionDiagnostics = createDiagnosticCollection();
44075
44089
  var typeofType = createTypeofType();
@@ -51595,7 +51609,7 @@ function createTypeChecker(host) {
51595
51609
  return type.flags & (128 /* StringLiteral */ | 256 /* NumberLiteral */) ? "" + type.value : void 0;
51596
51610
  }
51597
51611
  function getTypeForBindingElement(declaration) {
51598
- const checkMode = declaration.dotDotDotToken ? 64 /* RestBindingElement */ : 0 /* Normal */;
51612
+ const checkMode = declaration.dotDotDotToken ? 32 /* RestBindingElement */ : 0 /* Normal */;
51599
51613
  const parentType = getTypeForBindingElementParent(declaration.parent.parent, checkMode);
51600
51614
  return parentType && getBindingElementTypeFromParentType(
51601
51615
  declaration,
@@ -63762,7 +63776,7 @@ function createTypeChecker(host) {
63762
63776
  if (!couldContainTypeVariables(target)) {
63763
63777
  return;
63764
63778
  }
63765
- if (source === wildcardType) {
63779
+ if (source === wildcardType || source === blockedStringType) {
63766
63780
  const savePropagationType = propagationType;
63767
63781
  propagationType = source;
63768
63782
  inferFromTypes(target, target);
@@ -63819,6 +63833,10 @@ function createTypeChecker(host) {
63819
63833
  return;
63820
63834
  }
63821
63835
  if (!inference.isFixed) {
63836
+ const candidate = propagationType || source;
63837
+ if (candidate === blockedStringType) {
63838
+ return;
63839
+ }
63822
63840
  if (inference.priority === void 0 || priority < inference.priority) {
63823
63841
  inference.candidates = void 0;
63824
63842
  inference.contraCandidates = void 0;
@@ -63826,7 +63844,6 @@ function createTypeChecker(host) {
63826
63844
  inference.priority = priority;
63827
63845
  }
63828
63846
  if (priority === inference.priority) {
63829
- const candidate = propagationType || source;
63830
63847
  if (contravariant && !bivariant) {
63831
63848
  if (!contains(inference.contraCandidates, candidate)) {
63832
63849
  inference.contraCandidates = append(inference.contraCandidates, candidate);
@@ -64398,7 +64415,7 @@ function createTypeChecker(host) {
64398
64415
  const constraint = getConstraintOfTypeParameter(inference.typeParameter);
64399
64416
  if (constraint) {
64400
64417
  const instantiatedConstraint = instantiateType(constraint, context.nonFixingMapper);
64401
- if (!inferredType || inferredType === blockedStringType || !context.compareTypes(inferredType, getTypeWithThisArgument(instantiatedConstraint, inferredType))) {
64418
+ if (!inferredType || !context.compareTypes(inferredType, getTypeWithThisArgument(instantiatedConstraint, inferredType))) {
64402
64419
  inference.inferredType = fallbackType && context.compareTypes(fallbackType, getTypeWithThisArgument(instantiatedConstraint, fallbackType)) ? fallbackType : instantiatedConstraint;
64403
64420
  }
64404
64421
  }
@@ -65249,7 +65266,10 @@ function createTypeChecker(host) {
65249
65266
  let signature = links.effectsSignature;
65250
65267
  if (signature === void 0) {
65251
65268
  let funcType;
65252
- if (node.parent.kind === 244 /* ExpressionStatement */) {
65269
+ if (isBinaryExpression(node)) {
65270
+ const rightType = checkNonNullExpression(node.right);
65271
+ funcType = getSymbolHasInstanceMethodOfObjectType(rightType);
65272
+ } else if (node.parent.kind === 244 /* ExpressionStatement */) {
65253
65273
  funcType = getTypeOfDottedName(
65254
65274
  node.expression,
65255
65275
  /*diagnostic*/
@@ -66273,7 +66293,22 @@ function createTypeChecker(host) {
66273
66293
  }
66274
66294
  return type;
66275
66295
  }
66276
- const rightType = getTypeOfExpression(expr.right);
66296
+ const right = expr.right;
66297
+ const rightType = getTypeOfExpression(right);
66298
+ if (!isTypeDerivedFrom(rightType, globalObjectType)) {
66299
+ return type;
66300
+ }
66301
+ const signature = getEffectsSignature(expr);
66302
+ const predicate = signature && getTypePredicateOfSignature(signature);
66303
+ if (predicate && predicate.kind === 1 /* Identifier */ && predicate.parameterIndex === 0) {
66304
+ return getNarrowedType(
66305
+ type,
66306
+ predicate.type,
66307
+ assumeTrue,
66308
+ /*checkDerived*/
66309
+ true
66310
+ );
66311
+ }
66277
66312
  if (!isTypeDerivedFrom(rightType, globalFunctionType)) {
66278
66313
  return type;
66279
66314
  }
@@ -66525,7 +66560,7 @@ function createTypeChecker(host) {
66525
66560
  return type.flags & 2097152 /* Intersection */ ? some(type.types, isGenericTypeWithoutNullableConstraint) : !!(type.flags & 465829888 /* Instantiable */ && !maybeTypeOfKind(getBaseConstraintOrType(type), 98304 /* Nullable */));
66526
66561
  }
66527
66562
  function hasContextualTypeWithNoGenericTypes(node, checkMode) {
66528
- const contextualType = (isIdentifier(node) || isPropertyAccessExpression(node) || isElementAccessExpression(node)) && !((isJsxOpeningElement(node.parent) || isJsxSelfClosingElement(node.parent)) && node.parent.tagName === node) && (checkMode && checkMode & 64 /* RestBindingElement */ ? getContextualType(node, 8 /* SkipBindingPatterns */) : getContextualType(
66563
+ const contextualType = (isIdentifier(node) || isPropertyAccessExpression(node) || isElementAccessExpression(node)) && !((isJsxOpeningElement(node.parent) || isJsxSelfClosingElement(node.parent)) && node.parent.tagName === node) && (checkMode && checkMode & 32 /* RestBindingElement */ ? getContextualType(node, 8 /* SkipBindingPatterns */) : getContextualType(
66529
66564
  node,
66530
66565
  /*contextFlags*/
66531
66566
  void 0
@@ -67285,7 +67320,7 @@ function createTypeChecker(host) {
67285
67320
  function getContextualTypeForBindingElement(declaration, contextFlags) {
67286
67321
  const parent = declaration.parent.parent;
67287
67322
  const name = declaration.propertyName || declaration.name;
67288
- const parentType = getContextualTypeForVariableLikeDeclaration(parent, contextFlags) || parent.kind !== 208 /* BindingElement */ && parent.initializer && checkDeclarationInitializer(parent, declaration.dotDotDotToken ? 64 /* RestBindingElement */ : 0 /* Normal */);
67323
+ const parentType = getContextualTypeForVariableLikeDeclaration(parent, contextFlags) || parent.kind !== 208 /* BindingElement */ && parent.initializer && checkDeclarationInitializer(parent, declaration.dotDotDotToken ? 32 /* RestBindingElement */ : 0 /* Normal */);
67289
67324
  if (!parentType || isBindingPattern(name) || isComputedNonLiteralName(name))
67290
67325
  return void 0;
67291
67326
  if (parent.name.kind === 207 /* ArrayBindingPattern */) {
@@ -70131,7 +70166,9 @@ function createTypeChecker(host) {
70131
70166
  checkExpression(node.template);
70132
70167
  } else if (isJsxOpeningLikeElement(node)) {
70133
70168
  checkExpression(node.attributes);
70134
- } else if (node.kind !== 170 /* Decorator */) {
70169
+ } else if (isBinaryExpression(node)) {
70170
+ checkExpression(node.left);
70171
+ } else if (isCallOrNewExpression(node)) {
70135
70172
  forEach(node.arguments, (argument) => {
70136
70173
  checkExpression(argument);
70137
70174
  });
@@ -70204,6 +70241,8 @@ function createTypeChecker(host) {
70204
70241
  }
70205
70242
  } else if (node.kind === 170 /* Decorator */) {
70206
70243
  argCount = getDecoratorArgumentCount(node, signature);
70244
+ } else if (node.kind === 226 /* BinaryExpression */) {
70245
+ argCount = 1;
70207
70246
  } else if (isJsxOpeningLikeElement(node)) {
70208
70247
  callIsIncomplete = node.attributes.end === node.end;
70209
70248
  if (callIsIncomplete) {
@@ -70303,13 +70342,13 @@ function createTypeChecker(host) {
70303
70342
  return voidType;
70304
70343
  }
70305
70344
  const thisArgumentType = checkExpression(thisArgumentNode);
70306
- return isOptionalChainRoot(thisArgumentNode.parent) ? getNonNullableType(thisArgumentType) : isOptionalChain(thisArgumentNode.parent) ? removeOptionalTypeMarker(thisArgumentType) : thisArgumentType;
70345
+ return isRightSideOfInstanceofExpression(thisArgumentNode) ? thisArgumentType : isOptionalChainRoot(thisArgumentNode.parent) ? getNonNullableType(thisArgumentType) : isOptionalChain(thisArgumentNode.parent) ? removeOptionalTypeMarker(thisArgumentType) : thisArgumentType;
70307
70346
  }
70308
70347
  function inferTypeArguments(node, signature, args, checkMode, context) {
70309
70348
  if (isJsxOpeningLikeElement(node)) {
70310
70349
  return inferJsxTypeArguments(node, signature, checkMode, context);
70311
70350
  }
70312
- if (node.kind !== 170 /* Decorator */) {
70351
+ if (node.kind !== 170 /* Decorator */ && node.kind !== 226 /* BinaryExpression */) {
70313
70352
  const skipBindingPatterns = every(signature.typeParameters, (p) => !!getDefaultFromTypeParameter(p));
70314
70353
  const contextualType = getContextualType(node, skipBindingPatterns ? 8 /* SkipBindingPatterns */ : 0 /* None */);
70315
70354
  if (contextualType) {
@@ -70346,7 +70385,7 @@ function createTypeChecker(host) {
70346
70385
  }
70347
70386
  for (let i = 0; i < argCount; i++) {
70348
70387
  const arg = args[i];
70349
- if (arg.kind !== 232 /* OmittedExpression */ && !(checkMode & 32 /* IsForStringLiteralArgumentCompletions */ && hasSkipDirectInferenceFlag(arg))) {
70388
+ if (arg.kind !== 232 /* OmittedExpression */) {
70350
70389
  const paramType = getTypeAtPosition(signature, i);
70351
70390
  if (couldContainTypeVariables(paramType)) {
70352
70391
  const argType = checkExpressionWithContextualType(arg, paramType, context, checkMode);
@@ -70638,6 +70677,9 @@ function createTypeChecker(host) {
70638
70677
  }
70639
70678
  }
70640
70679
  function getThisArgumentOfCall(node) {
70680
+ if (node.kind === 226 /* BinaryExpression */) {
70681
+ return node.right;
70682
+ }
70641
70683
  const expression = node.kind === 213 /* CallExpression */ ? node.expression : node.kind === 215 /* TaggedTemplateExpression */ ? node.tag : node.kind === 170 /* Decorator */ && !legacyDecorators ? node.expression : void 0;
70642
70684
  if (expression) {
70643
70685
  const callee = skipOuterExpressions(expression);
@@ -70666,6 +70708,9 @@ function createTypeChecker(host) {
70666
70708
  if (node.kind === 170 /* Decorator */) {
70667
70709
  return getEffectiveDecoratorArguments(node);
70668
70710
  }
70711
+ if (node.kind === 226 /* BinaryExpression */) {
70712
+ return [node.left];
70713
+ }
70669
70714
  if (isJsxOpeningLikeElement(node)) {
70670
70715
  return node.attributes.properties.length > 0 || isJsxOpeningElement(node) && node.parent.children.length > 0 ? [node.attributes] : emptyArray;
70671
70716
  }
@@ -70935,9 +70980,10 @@ function createTypeChecker(host) {
70935
70980
  const isTaggedTemplate = node.kind === 215 /* TaggedTemplateExpression */;
70936
70981
  const isDecorator2 = node.kind === 170 /* Decorator */;
70937
70982
  const isJsxOpeningOrSelfClosingElement = isJsxOpeningLikeElement(node);
70983
+ const isInstanceof = node.kind === 226 /* BinaryExpression */;
70938
70984
  const reportErrors2 = !isInferencePartiallyBlocked && !candidatesOutArray;
70939
70985
  let typeArguments;
70940
- if (!isDecorator2 && !isSuperCall(node)) {
70986
+ if (!isDecorator2 && !isInstanceof && !isSuperCall(node)) {
70941
70987
  typeArguments = node.typeArguments;
70942
70988
  if (isTaggedTemplate || isJsxOpeningOrSelfClosingElement || node.expression.kind !== 108 /* SuperKeyword */) {
70943
70989
  forEach(typeArguments, checkSourceElement);
@@ -70949,7 +70995,6 @@ function createTypeChecker(host) {
70949
70995
  const args = getEffectiveCallArguments(node);
70950
70996
  const isSingleNonGenericCandidate = candidates.length === 1 && !candidates[0].typeParameters;
70951
70997
  let argCheckMode = !isDecorator2 && !isSingleNonGenericCandidate && some(args, isContextSensitive) ? 4 /* SkipContextSensitive */ : 0 /* Normal */;
70952
- argCheckMode |= checkMode & 32 /* IsForStringLiteralArgumentCompletions */;
70953
70998
  let candidatesForArgumentError;
70954
70999
  let candidateForArgumentArityError;
70955
71000
  let candidateForTypeArgumentError;
@@ -70967,6 +71012,9 @@ function createTypeChecker(host) {
70967
71012
  result = getCandidateForOverloadFailure(node, candidates, args, !!candidatesOutArray, checkMode);
70968
71013
  getNodeLinks(node).resolvedSignature = result;
70969
71014
  if (reportErrors2) {
71015
+ if (!headMessage && isInstanceof) {
71016
+ headMessage = Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_assignable_to_the_first_argument_of_the_right_hand_side_s_Symbol_hasInstance_method;
71017
+ }
70970
71018
  if (candidatesForArgumentError) {
70971
71019
  if (candidatesForArgumentError.length === 1 || candidatesForArgumentError.length > 3) {
70972
71020
  const last2 = candidatesForArgumentError[candidatesForArgumentError.length - 1];
@@ -71753,6 +71801,30 @@ function createTypeChecker(host) {
71753
71801
  }
71754
71802
  return resolveCall(node, signatures, candidatesOutArray, checkMode, 0 /* None */);
71755
71803
  }
71804
+ function resolveInstanceofExpression(node, candidatesOutArray, checkMode) {
71805
+ const rightType = checkExpression(node.right);
71806
+ if (!isTypeAny(rightType)) {
71807
+ const hasInstanceMethodType = getSymbolHasInstanceMethodOfObjectType(rightType);
71808
+ if (hasInstanceMethodType) {
71809
+ const apparentType = getApparentType(hasInstanceMethodType);
71810
+ if (isErrorType(apparentType)) {
71811
+ return resolveErrorCall(node);
71812
+ }
71813
+ const callSignatures = getSignaturesOfType(apparentType, 0 /* Call */);
71814
+ const constructSignatures = getSignaturesOfType(apparentType, 1 /* Construct */);
71815
+ if (isUntypedFunctionCall(hasInstanceMethodType, apparentType, callSignatures.length, constructSignatures.length)) {
71816
+ return resolveUntypedCall(node);
71817
+ }
71818
+ if (callSignatures.length) {
71819
+ return resolveCall(node, callSignatures, candidatesOutArray, checkMode, 0 /* None */);
71820
+ }
71821
+ } else if (!(typeHasCallOrConstructSignatures(rightType) || isTypeSubtypeOf(rightType, globalFunctionType))) {
71822
+ error(node.right, Diagnostics.The_right_hand_side_of_an_instanceof_expression_must_be_either_of_type_any_a_class_function_or_other_type_assignable_to_the_Function_interface_type_or_an_object_type_with_a_Symbol_hasInstance_method);
71823
+ return resolveErrorCall(node);
71824
+ }
71825
+ }
71826
+ return anySignature;
71827
+ }
71756
71828
  function isPotentiallyUncalledDecorator(decorator, signatures) {
71757
71829
  return signatures.length && every(signatures, (signature) => signature.minArgumentCount === 0 && !signatureHasRestParameter(signature) && signature.parameters.length < getDecoratorArgumentCount(decorator, signature));
71758
71830
  }
@@ -71769,6 +71841,8 @@ function createTypeChecker(host) {
71769
71841
  case 286 /* JsxOpeningElement */:
71770
71842
  case 285 /* JsxSelfClosingElement */:
71771
71843
  return resolveJsxOpeningLikeElement(node, candidatesOutArray, checkMode);
71844
+ case 226 /* BinaryExpression */:
71845
+ return resolveInstanceofExpression(node, candidatesOutArray, checkMode);
71772
71846
  }
71773
71847
  Debug.assertNever(node, "Branch in 'resolveSignature' should be unreachable.");
71774
71848
  }
@@ -73727,16 +73801,35 @@ function createTypeChecker(host) {
73727
73801
  function isConstEnumSymbol(symbol) {
73728
73802
  return (symbol.flags & 128 /* ConstEnum */) !== 0;
73729
73803
  }
73730
- function checkInstanceOfExpression(left, right, leftType, rightType) {
73804
+ function getSymbolHasInstanceMethodOfObjectType(type) {
73805
+ const hasInstancePropertyName = getPropertyNameForKnownSymbolName("hasInstance");
73806
+ const hasInstanceProperty = getPropertyOfObjectType(type, hasInstancePropertyName);
73807
+ if (hasInstanceProperty) {
73808
+ const hasInstancePropertyType = getTypeOfSymbol(hasInstanceProperty);
73809
+ if (hasInstancePropertyType && getSignaturesOfType(hasInstancePropertyType, 0 /* Call */).length !== 0) {
73810
+ return hasInstancePropertyType;
73811
+ }
73812
+ }
73813
+ }
73814
+ function checkInstanceOfExpression(left, right, leftType, rightType, checkMode) {
73731
73815
  if (leftType === silentNeverType || rightType === silentNeverType) {
73732
73816
  return silentNeverType;
73733
73817
  }
73734
73818
  if (!isTypeAny(leftType) && allTypesAssignableToKind(leftType, 402784252 /* Primitive */)) {
73735
73819
  error(left, Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter);
73736
73820
  }
73737
- if (!(isTypeAny(rightType) || typeHasCallOrConstructSignatures(rightType) || isTypeSubtypeOf(rightType, globalFunctionType))) {
73738
- error(right, Diagnostics.The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type);
73821
+ Debug.assert(isInstanceOfExpression(left.parent));
73822
+ const signature = getResolvedSignature(
73823
+ left.parent,
73824
+ /*candidatesOutArray*/
73825
+ void 0,
73826
+ checkMode
73827
+ );
73828
+ if (signature === resolvingSignature) {
73829
+ return silentNeverType;
73739
73830
  }
73831
+ const returnType = getReturnTypeOfSignature(signature);
73832
+ checkTypeAssignableTo(returnType, booleanType, right, Diagnostics.An_object_s_Symbol_hasInstance_method_must_return_a_boolean_value_for_it_to_be_used_on_the_right_hand_side_of_an_instanceof_expression);
73740
73833
  return booleanType;
73741
73834
  }
73742
73835
  function hasEmptyObjectIntersection(type) {
@@ -74274,7 +74367,7 @@ function createTypeChecker(host) {
74274
74367
  case 36 /* ExclamationEqualsToken */:
74275
74368
  case 37 /* EqualsEqualsEqualsToken */:
74276
74369
  case 38 /* ExclamationEqualsEqualsToken */:
74277
- if (!(checkMode && checkMode & 128 /* TypeOnly */)) {
74370
+ if (!(checkMode && checkMode & 64 /* TypeOnly */)) {
74278
74371
  if ((isLiteralExpressionOfObject(left) || isLiteralExpressionOfObject(right)) && // only report for === and !== in JS, not == or !=
74279
74372
  (!isInJSFile(left) || (operator === 37 /* EqualsEqualsEqualsToken */ || operator === 38 /* ExclamationEqualsEqualsToken */))) {
74280
74373
  const eqType = operator === 35 /* EqualsEqualsToken */ || operator === 37 /* EqualsEqualsEqualsToken */;
@@ -74285,7 +74378,7 @@ function createTypeChecker(host) {
74285
74378
  }
74286
74379
  return booleanType;
74287
74380
  case 104 /* InstanceOfKeyword */:
74288
- return checkInstanceOfExpression(left, right, leftType, rightType);
74381
+ return checkInstanceOfExpression(left, right, leftType, rightType, checkMode);
74289
74382
  case 103 /* InKeyword */:
74290
74383
  return checkInExpression(left, right, leftType, rightType);
74291
74384
  case 56 /* AmpersandAmpersandToken */:
@@ -74922,7 +75015,7 @@ function createTypeChecker(host) {
74922
75015
  }
74923
75016
  }
74924
75017
  const startInvocationCount = flowInvocationCount;
74925
- const type = checkExpression(node, 128 /* TypeOnly */);
75018
+ const type = checkExpression(node, 64 /* TypeOnly */);
74926
75019
  if (flowInvocationCount !== startInvocationCount) {
74927
75020
  const cache = flowTypeCache || (flowTypeCache = []);
74928
75021
  cache[getNodeId(node)] = type;
@@ -77388,7 +77481,7 @@ function createTypeChecker(host) {
77388
77481
  checkComputedPropertyName(node.propertyName);
77389
77482
  }
77390
77483
  const parent = node.parent.parent;
77391
- const parentCheckMode = node.dotDotDotToken ? 64 /* RestBindingElement */ : 0 /* Normal */;
77484
+ const parentCheckMode = node.dotDotDotToken ? 32 /* RestBindingElement */ : 0 /* Normal */;
77392
77485
  const parentType = getTypeForBindingElementParent(parent, parentCheckMode);
77393
77486
  const name = node.propertyName || node.name;
77394
77487
  if (parentType && !isBindingPattern(name)) {
@@ -77529,29 +77622,6 @@ function createTypeChecker(host) {
77529
77622
  }
77530
77623
  checkCollisionsForDeclarationName(node, node.name);
77531
77624
  }
77532
- function canHaveLiteralInitializer2(node2) {
77533
- switch (node2.kind) {
77534
- case 172 /* PropertyDeclaration */:
77535
- case 171 /* PropertySignature */:
77536
- return !hasEffectiveModifier(node2, 8 /* Private */);
77537
- case 169 /* Parameter */:
77538
- case 260 /* VariableDeclaration */:
77539
- return true;
77540
- }
77541
- return false;
77542
- }
77543
- function shouldPrintWithInitializer(node2) {
77544
- return canHaveLiteralInitializer2(node2) && isLiteralConstDeclaration(node2);
77545
- }
77546
- function isPrivateDeclaration(node2) {
77547
- return hasEffectiveModifier(node2, 8 /* Private */) || isPrivateIdentifierClassElementDeclaration(node2);
77548
- }
77549
- if (getEmitDeclarations(compilerOptions) && !(symbol.flags & (2048 /* TypeLiteral */ | 131072 /* Signature */)) && !shouldPrintWithInitializer(node) && !isPrivateDeclaration(node)) {
77550
- const widenedLiteralType = getWidenedLiteralType(type);
77551
- if (!isTypeIdenticalTo(type, widenedLiteralType)) {
77552
- ambiguousVariableDeclarationsWhenWidened.push([node, type, widenedLiteralType]);
77553
- }
77554
- }
77555
77625
  }
77556
77626
  function errorNextVariableOrPropertyDeclarationMustHaveSameType(firstDeclaration, firstType, nextDeclaration, nextType) {
77557
77627
  const nextDeclarationName = getNameOfDeclaration(nextDeclaration);
@@ -80720,6 +80790,12 @@ function createTypeChecker(host) {
80720
80790
  case 234 /* AsExpression */:
80721
80791
  case 217 /* ParenthesizedExpression */:
80722
80792
  checkAssertionDeferred(node);
80793
+ break;
80794
+ case 226 /* BinaryExpression */:
80795
+ if (isInstanceOfExpression(node)) {
80796
+ resolveUntypedCall(node);
80797
+ }
80798
+ break;
80723
80799
  }
80724
80800
  currentNode = saveCurrentNode;
80725
80801
  (_b = tracing) == null ? void 0 : _b.pop();
@@ -80767,7 +80843,6 @@ function createTypeChecker(host) {
80767
80843
  clear(potentialWeakMapSetCollisions);
80768
80844
  clear(potentialReflectCollisions);
80769
80845
  clear(potentialUnusedRenamedBindingElementsInTypes);
80770
- clear(ambiguousVariableDeclarationsWhenWidened);
80771
80846
  forEach(node.statements, checkSourceElement);
80772
80847
  checkSourceElement(node.endOfFileToken);
80773
80848
  checkDeferredNodes(node);
@@ -80786,23 +80861,6 @@ function createTypeChecker(host) {
80786
80861
  checkPotentialUncheckedRenamedBindingElementsInTypes();
80787
80862
  }
80788
80863
  });
80789
- addLazyDiagnostic(() => {
80790
- function isVisibleExternally(elem) {
80791
- if (isOmittedExpression(elem)) {
80792
- return false;
80793
- }
80794
- if (isBindingPattern(elem.name)) {
80795
- return some(elem.name.elements, isVisibleExternally);
80796
- } else {
80797
- return isDeclarationVisible(elem);
80798
- }
80799
- }
80800
- for (const [node2, type, widenedLiteralType] of ambiguousVariableDeclarationsWhenWidened) {
80801
- if (isVisibleExternally(node2)) {
80802
- error(node2.name, Diagnostics.The_type_of_this_declaration_is_ambiguous_and_may_be_observed_as_either_0_or_1, typeToString(widenedLiteralType), typeToString(type));
80803
- }
80804
- }
80805
- });
80806
80864
  if (compilerOptions.importsNotUsedAsValues === 2 /* Error */ && !node.isDeclarationFile && isExternalModule(node)) {
80807
80865
  checkImportsForTypeOnlyConversion(node);
80808
80866
  }
@@ -80825,9 +80883,6 @@ function createTypeChecker(host) {
80825
80883
  forEach(potentialReflectCollisions, checkReflectCollision);
80826
80884
  clear(potentialReflectCollisions);
80827
80885
  }
80828
- if (ambiguousVariableDeclarationsWhenWidened.length) {
80829
- clear(ambiguousVariableDeclarationsWhenWidened);
80830
- }
80831
80886
  links.flags |= 1 /* TypeChecked */;
80832
80887
  }
80833
80888
  }
@@ -81357,6 +81412,13 @@ function createTypeChecker(host) {
81357
81412
  case 102 /* ImportKeyword */:
81358
81413
  case 105 /* NewKeyword */:
81359
81414
  return isMetaProperty(node.parent) ? checkMetaPropertyKeyword(node.parent).symbol : void 0;
81415
+ case 104 /* InstanceOfKeyword */:
81416
+ if (isBinaryExpression(node.parent)) {
81417
+ const type = getTypeOfExpression(node.parent.right);
81418
+ const hasInstanceMethodType = getSymbolHasInstanceMethodOfObjectType(type);
81419
+ return (hasInstanceMethodType == null ? void 0 : hasInstanceMethodType.symbol) ?? type.symbol;
81420
+ }
81421
+ return void 0;
81360
81422
  case 236 /* MetaProperty */:
81361
81423
  return checkExpression(node).symbol;
81362
81424
  case 295 /* JsxNamespacedName */: