@typescript-deploys/pr-build 5.2.0-pr-55034-8 → 5.2.0-pr-55052-3

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
@@ -6668,6 +6668,9 @@ var Diagnostics = {
6668
6668
  await_using_statements_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules: diag(2852, 1 /* Error */, "await_using_statements_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules_2852", "'await using' statements are only allowed within async functions and at the top levels of modules."),
6669
6669
  await_using_statements_are_only_allowed_at_the_top_level_of_a_file_when_that_file_is_a_module_but_this_file_has_no_imports_or_exports_Consider_adding_an_empty_export_to_make_this_file_a_module: diag(2853, 1 /* Error */, "await_using_statements_are_only_allowed_at_the_top_level_of_a_file_when_that_file_is_a_module_but_th_2853", "'await using' statements are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module."),
6670
6670
  Top_level_await_using_statements_are_only_allowed_when_the_module_option_is_set_to_es2022_esnext_system_node16_or_nodenext_and_the_target_option_is_set_to_es2017_or_higher: diag(2854, 1 /* Error */, "Top_level_await_using_statements_are_only_allowed_when_the_module_option_is_set_to_es2022_esnext_sys_2854", "Top-level 'await using' statements are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', or 'nodenext', and the 'target' option is set to 'es2017' or higher."),
6671
+ 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(2855, 1 /* Error */, "The_left_hand_side_of_an_instanceof_expression_must_be_assignable_to_the_first_argument_of_the_right_2855", "The left-hand side of an 'instanceof' expression must be assignable to the first argument of the right-hand side's '[Symbol.hasInstance]' method."),
6672
+ 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(2856, 1 /* Error */, "An_object_s_Symbol_hasInstance_method_must_return_a_boolean_value_for_it_to_be_used_on_the_right_han_2856", "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."),
6673
+ The_right_hand_side_of_an_instanceof_expression_must_be_either_of_type_any_an_object_type_with_a_Symbol_hasInstance_method_or_a_type_assignable_to_the_Function_interface_type: diag(2857, 1 /* Error */, "The_right_hand_side_of_an_instanceof_expression_must_be_either_of_type_any_an_object_type_with_a_Sym_2857", "The right-hand side of an 'instanceof' expression must be either of type 'any', an object type with a '[Symbol.hasInstance]()' method, or a type assignable to the 'Function' interface type."),
6671
6674
  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}'."),
6672
6675
  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}'."),
6673
6676
  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}'."),
@@ -10991,6 +10994,7 @@ function isLeftHandSideExpressionKind(kind) {
10991
10994
  case 236 /* MetaProperty */:
10992
10995
  case 102 /* ImportKeyword */:
10993
10996
  case 282 /* MissingDeclaration */:
10997
+ case 237 /* SyntheticExpression */:
10994
10998
  return true;
10995
10999
  default:
10996
11000
  return false;
@@ -24271,6 +24275,9 @@ function isNonNullExpression(node) {
24271
24275
  function isMetaProperty(node) {
24272
24276
  return node.kind === 236 /* MetaProperty */;
24273
24277
  }
24278
+ function isSyntheticExpression(node) {
24279
+ return node.kind === 237 /* SyntheticExpression */;
24280
+ }
24274
24281
  function isPartiallyEmittedExpression(node) {
24275
24282
  return node.kind === 360 /* PartiallyEmittedExpression */;
24276
24283
  }
@@ -43863,6 +43870,7 @@ function createTypeChecker(host) {
43863
43870
  var potentialReflectCollisions = [];
43864
43871
  var potentialUnusedRenamedBindingElementsInTypes = [];
43865
43872
  var awaitedTypeStack = [];
43873
+ var hasGlobalSymbolHasInstanceProperty;
43866
43874
  var diagnostics = createDiagnosticCollection();
43867
43875
  var suggestionDiagnostics = createDiagnosticCollection();
43868
43876
  var typeofType = createTypeofType();
@@ -63012,12 +63020,7 @@ function createTypeChecker(host) {
63012
63020
  callback(getTypeAtPosition(source, i), getTypeAtPosition(target, i));
63013
63021
  }
63014
63022
  if (targetRestType) {
63015
- callback(getRestTypeAtPosition(
63016
- source,
63017
- paramCount,
63018
- /*readonly*/
63019
- isConstTypeVariable(targetRestType)
63020
- ), targetRestType);
63023
+ callback(getRestTypeAtPosition(source, paramCount), targetRestType);
63021
63024
  }
63022
63025
  }
63023
63026
  function applyToReturnTypes(source, target, callback) {
@@ -65910,6 +65913,15 @@ function createTypeChecker(host) {
65910
65913
  return type;
65911
65914
  }
65912
65915
  const rightType = getTypeOfExpression(expr.right);
65916
+ const hasInstanceMethodType = getSymbolHasInstanceMethodOfObjectType(rightType);
65917
+ if (hasInstanceMethodType) {
65918
+ const syntheticCall = createSyntheticHasInstanceMethodCall(left, expr.right, type, hasInstanceMethodType);
65919
+ const signature = getEffectsSignature(syntheticCall);
65920
+ const predicate = signature && getTypePredicateOfSignature(signature);
65921
+ if (predicate && (predicate.kind === 0 /* This */ || predicate.kind === 1 /* Identifier */)) {
65922
+ return narrowTypeByTypePredicate(type, predicate, syntheticCall, assumeTrue);
65923
+ }
65924
+ }
65913
65925
  if (!isTypeDerivedFrom(rightType, globalFunctionType)) {
65914
65926
  return type;
65915
65927
  }
@@ -65989,8 +66001,12 @@ function createTypeChecker(host) {
65989
66001
  }
65990
66002
  function narrowTypeByTypePredicate(type, predicate, callExpression, assumeTrue) {
65991
66003
  if (predicate.type && !(isTypeAny(type) && (predicate.type === globalObjectType || predicate.type === globalFunctionType))) {
65992
- const predicateArgument = getTypePredicateArgument(predicate, callExpression);
66004
+ let predicateArgument = getTypePredicateArgument(predicate, callExpression);
65993
66005
  if (predicateArgument) {
66006
+ if (isSyntheticExpression(predicateArgument) && predicate.parameterIndex === 0 && isSyntheticHasInstanceMethodCall(callExpression)) {
66007
+ Debug.assertNode(predicateArgument.parent, isExpression);
66008
+ predicateArgument = predicateArgument.parent;
66009
+ }
65994
66010
  if (isMatchingReference(reference, predicateArgument)) {
65995
66011
  return getNarrowedType(
65996
66012
  type,
@@ -70567,7 +70583,7 @@ function createTypeChecker(host) {
70567
70583
  }
70568
70584
  return createDiagnosticForNodeArray(getSourceFileOfNode(node), typeArguments, Diagnostics.Expected_0_type_arguments_but_got_1, belowArgCount === -Infinity ? aboveArgCount : belowArgCount, argCount);
70569
70585
  }
70570
- function resolveCall(node, signatures, candidatesOutArray, checkMode, callChainFlags, headMessage) {
70586
+ function resolveCall(node, signatures, candidatesOutArray, checkMode, callChainFlags, headMessageCallback) {
70571
70587
  const isTaggedTemplate = node.kind === 215 /* TaggedTemplateExpression */;
70572
70588
  const isDecorator2 = node.kind === 170 /* Decorator */;
70573
70589
  const isJsxOpeningOrSelfClosingElement = isJsxOpeningLikeElement(node);
@@ -70610,6 +70626,7 @@ function createTypeChecker(host) {
70610
70626
  chain = chainDiagnosticMessages(chain, Diagnostics.The_last_overload_gave_the_following_error);
70611
70627
  chain = chainDiagnosticMessages(chain, Diagnostics.No_overload_matches_this_call);
70612
70628
  }
70629
+ const headMessage = headMessageCallback == null ? void 0 : headMessageCallback();
70613
70630
  if (headMessage) {
70614
70631
  chain = chainDiagnosticMessages(chain, headMessage);
70615
70632
  }
@@ -70677,6 +70694,7 @@ function createTypeChecker(host) {
70677
70694
  map(diags, createDiagnosticMessageChainFromDiagnostic),
70678
70695
  Diagnostics.No_overload_matches_this_call
70679
70696
  );
70697
+ const headMessage = headMessageCallback == null ? void 0 : headMessageCallback();
70680
70698
  if (headMessage) {
70681
70699
  chain = chainDiagnosticMessages(chain, headMessage);
70682
70700
  }
@@ -70692,21 +70710,21 @@ function createTypeChecker(host) {
70692
70710
  diagnostics.add(diag2);
70693
70711
  }
70694
70712
  } else if (candidateForArgumentArityError) {
70695
- diagnostics.add(getArgumentArityError(node, [candidateForArgumentArityError], args, headMessage));
70713
+ diagnostics.add(getArgumentArityError(node, [candidateForArgumentArityError], args, headMessageCallback == null ? void 0 : headMessageCallback()));
70696
70714
  } else if (candidateForTypeArgumentError) {
70697
70715
  checkTypeArguments(
70698
70716
  candidateForTypeArgumentError,
70699
70717
  node.typeArguments,
70700
70718
  /*reportErrors*/
70701
70719
  true,
70702
- headMessage
70720
+ headMessageCallback == null ? void 0 : headMessageCallback()
70703
70721
  );
70704
70722
  } else {
70705
70723
  const signaturesWithCorrectTypeArgumentArity = filter(signatures, (s) => hasCorrectTypeArgumentArity(s, typeArguments));
70706
70724
  if (signaturesWithCorrectTypeArgumentArity.length === 0) {
70707
- diagnostics.add(getTypeArgumentArityError(node, signatures, typeArguments, headMessage));
70725
+ diagnostics.add(getTypeArgumentArityError(node, signatures, typeArguments, headMessageCallback == null ? void 0 : headMessageCallback()));
70708
70726
  } else {
70709
- diagnostics.add(getArgumentArityError(node, signaturesWithCorrectTypeArgumentArity, args, headMessage));
70727
+ diagnostics.add(getArgumentArityError(node, signaturesWithCorrectTypeArgumentArity, args, headMessageCallback == null ? void 0 : headMessageCallback()));
70710
70728
  }
70711
70729
  }
70712
70730
  }
@@ -71014,7 +71032,7 @@ function createTypeChecker(host) {
71014
71032
  error(node, Diagnostics.Value_of_type_0_is_not_callable_Did_you_mean_to_include_new, typeToString(funcType));
71015
71033
  return resolveErrorCall(node);
71016
71034
  }
71017
- return resolveCall(node, callSignatures, candidatesOutArray, checkMode, callChainFlags);
71035
+ return resolveCall(node, callSignatures, candidatesOutArray, checkMode, callChainFlags, () => isSyntheticHasInstanceMethodCall(node) ? 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 : void 0);
71018
71036
  }
71019
71037
  function isGenericFunctionReturningFunction(signature) {
71020
71038
  return !!(signature.typeParameters && isFunctionType(getReturnTypeOfSignature(signature)));
@@ -71311,7 +71329,7 @@ function createTypeChecker(host) {
71311
71329
  invocationErrorRecovery(apparentType, 0 /* Call */, diag2);
71312
71330
  return resolveErrorCall(node);
71313
71331
  }
71314
- return resolveCall(node, callSignatures, candidatesOutArray, checkMode, 0 /* None */, headMessage);
71332
+ return resolveCall(node, callSignatures, candidatesOutArray, checkMode, 0 /* None */, () => headMessage);
71315
71333
  }
71316
71334
  function createSignatureForJSXIntrinsic(node, result) {
71317
71335
  const namespace = getJsxNamespaceAt(node);
@@ -72122,7 +72140,7 @@ function createTypeChecker(host) {
72122
72140
  }
72123
72141
  return void 0;
72124
72142
  }
72125
- function getRestTypeAtPosition(source, pos, readonly) {
72143
+ function getRestTypeAtPosition(source, pos) {
72126
72144
  const parameterCount = getParameterCount(source);
72127
72145
  const minArgumentCount = getMinArgumentCount(source);
72128
72146
  const restType = getEffectiveRestType(source);
@@ -72145,7 +72163,13 @@ function createTypeChecker(host) {
72145
72163
  names.push(name);
72146
72164
  }
72147
72165
  }
72148
- return createTupleType(types, flags, readonly, length(names) === length(types) ? names : void 0);
72166
+ return createTupleType(
72167
+ types,
72168
+ flags,
72169
+ /*readonly*/
72170
+ false,
72171
+ length(names) === length(types) ? names : void 0
72172
+ );
72149
72173
  }
72150
72174
  function getParameterCount(signature) {
72151
72175
  const length2 = signature.parameters.length;
@@ -73338,6 +73362,32 @@ function createTypeChecker(host) {
73338
73362
  function isConstEnumSymbol(symbol) {
73339
73363
  return (symbol.flags & 128 /* ConstEnum */) !== 0;
73340
73364
  }
73365
+ function getSymbolHasInstanceMethodOfObjectType(type) {
73366
+ const hasInstancePropertyName = getPropertyNameForKnownSymbolName("hasInstance");
73367
+ const hasInstanceProperty = getPropertyOfObjectType(type, hasInstancePropertyName);
73368
+ if (hasInstanceProperty) {
73369
+ const hasInstancePropertyType = getTypeOfSymbol(hasInstanceProperty);
73370
+ if (hasInstancePropertyType && getSignaturesOfType(hasInstancePropertyType, 0 /* Call */).length !== 0) {
73371
+ return hasInstancePropertyType;
73372
+ }
73373
+ }
73374
+ }
73375
+ function createSyntheticHasInstanceMethodCall(left, right, leftType, hasInstanceMethodType) {
73376
+ const syntheticExpression = createSyntheticExpression(right, hasInstanceMethodType);
73377
+ const syntheticArgument = createSyntheticExpression(left, leftType);
73378
+ const syntheticCall = parseNodeFactory.createCallExpression(
73379
+ syntheticExpression,
73380
+ /*typeArguments*/
73381
+ void 0,
73382
+ [syntheticArgument]
73383
+ );
73384
+ setParent(syntheticCall, left.parent);
73385
+ setTextRange(syntheticCall, left.parent);
73386
+ return syntheticCall;
73387
+ }
73388
+ function isSyntheticHasInstanceMethodCall(node) {
73389
+ return isSyntheticExpression(node.expression) && node.arguments.length === 1 && isSyntheticExpression(node.arguments[0]) && isBinaryExpression(node.parent) && node.parent.operatorToken.kind === 104 /* InstanceOfKeyword */ && node.parent.right === node.expression.parent && node.parent.left === node.arguments[0].parent;
73390
+ }
73341
73391
  function checkInstanceOfExpression(left, right, leftType, rightType) {
73342
73392
  if (leftType === silentNeverType || rightType === silentNeverType) {
73343
73393
  return silentNeverType;
@@ -73345,8 +73395,31 @@ function createTypeChecker(host) {
73345
73395
  if (!isTypeAny(leftType) && allTypesAssignableToKind(leftType, 402784252 /* Primitive */)) {
73346
73396
  error(left, Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter);
73347
73397
  }
73348
- if (!(isTypeAny(rightType) || typeHasCallOrConstructSignatures(rightType) || isTypeSubtypeOf(rightType, globalFunctionType))) {
73349
- 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);
73398
+ if (!isTypeAny(rightType)) {
73399
+ const hasInstanceMethodType = getSymbolHasInstanceMethodOfObjectType(rightType);
73400
+ if (hasInstanceMethodType) {
73401
+ const cache = hasInstanceMethodType;
73402
+ if (cache.hasSimpleUnrestrictedSingleCallSignature === void 0) {
73403
+ const signature = getSingleCallSignature(hasInstanceMethodType);
73404
+ cache.hasSimpleUnrestrictedSingleCallSignature = !!signature && signature.parameters.length === 1 && !!(getTypeOfSymbol(signature.parameters[0]).flags & 3 /* AnyOrUnknown */) && !!signature.resolvedReturnType && !!(signature.resolvedReturnType.flags & 16 /* Boolean */);
73405
+ }
73406
+ if (!cache.hasSimpleUnrestrictedSingleCallSignature) {
73407
+ const syntheticCall = createSyntheticHasInstanceMethodCall(left, right, leftType, hasInstanceMethodType);
73408
+ const returnType = getReturnTypeOfSignature(getResolvedSignature(syntheticCall));
73409
+ 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);
73410
+ }
73411
+ }
73412
+ if (!(hasInstanceMethodType || typeHasCallOrConstructSignatures(rightType) || isTypeSubtypeOf(rightType, globalFunctionType))) {
73413
+ if (hasGlobalSymbolHasInstanceProperty === void 0) {
73414
+ const globalESSymbolConstructorSymbol = getGlobalESSymbolConstructorTypeSymbol(
73415
+ /*reportErrors*/
73416
+ false
73417
+ );
73418
+ hasGlobalSymbolHasInstanceProperty = !!globalESSymbolConstructorSymbol && getMembersOfSymbol(globalESSymbolConstructorSymbol).has("hasInstance");
73419
+ }
73420
+ const message = hasGlobalSymbolHasInstanceProperty ? Diagnostics.The_right_hand_side_of_an_instanceof_expression_must_be_either_of_type_any_an_object_type_with_a_Symbol_hasInstance_method_or_a_type_assignable_to_the_Function_interface_type : Diagnostics.The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type;
73421
+ error(right, message);
73422
+ }
73350
73423
  }
73351
73424
  return booleanType;
73352
73425
  }
package/lib/tsserver.js CHANGED
@@ -10189,6 +10189,9 @@ var Diagnostics = {
10189
10189
  await_using_statements_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules: diag(2852, 1 /* Error */, "await_using_statements_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules_2852", "'await using' statements are only allowed within async functions and at the top levels of modules."),
10190
10190
  await_using_statements_are_only_allowed_at_the_top_level_of_a_file_when_that_file_is_a_module_but_this_file_has_no_imports_or_exports_Consider_adding_an_empty_export_to_make_this_file_a_module: diag(2853, 1 /* Error */, "await_using_statements_are_only_allowed_at_the_top_level_of_a_file_when_that_file_is_a_module_but_th_2853", "'await using' statements are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module."),
10191
10191
  Top_level_await_using_statements_are_only_allowed_when_the_module_option_is_set_to_es2022_esnext_system_node16_or_nodenext_and_the_target_option_is_set_to_es2017_or_higher: diag(2854, 1 /* Error */, "Top_level_await_using_statements_are_only_allowed_when_the_module_option_is_set_to_es2022_esnext_sys_2854", "Top-level 'await using' statements are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', or 'nodenext', and the 'target' option is set to 'es2017' or higher."),
10192
+ 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(2855, 1 /* Error */, "The_left_hand_side_of_an_instanceof_expression_must_be_assignable_to_the_first_argument_of_the_right_2855", "The left-hand side of an 'instanceof' expression must be assignable to the first argument of the right-hand side's '[Symbol.hasInstance]' method."),
10193
+ 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(2856, 1 /* Error */, "An_object_s_Symbol_hasInstance_method_must_return_a_boolean_value_for_it_to_be_used_on_the_right_han_2856", "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."),
10194
+ The_right_hand_side_of_an_instanceof_expression_must_be_either_of_type_any_an_object_type_with_a_Symbol_hasInstance_method_or_a_type_assignable_to_the_Function_interface_type: diag(2857, 1 /* Error */, "The_right_hand_side_of_an_instanceof_expression_must_be_either_of_type_any_an_object_type_with_a_Sym_2857", "The right-hand side of an 'instanceof' expression must be either of type 'any', an object type with a '[Symbol.hasInstance]()' method, or a type assignable to the 'Function' interface type."),
10192
10195
  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}'."),
10193
10196
  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}'."),
10194
10197
  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}'."),
@@ -14662,6 +14665,7 @@ function isLeftHandSideExpressionKind(kind) {
14662
14665
  case 236 /* MetaProperty */:
14663
14666
  case 102 /* ImportKeyword */:
14664
14667
  case 282 /* MissingDeclaration */:
14668
+ case 237 /* SyntheticExpression */:
14665
14669
  return true;
14666
14670
  default:
14667
14671
  return false;
@@ -48570,6 +48574,7 @@ function createTypeChecker(host) {
48570
48574
  var potentialReflectCollisions = [];
48571
48575
  var potentialUnusedRenamedBindingElementsInTypes = [];
48572
48576
  var awaitedTypeStack = [];
48577
+ var hasGlobalSymbolHasInstanceProperty;
48573
48578
  var diagnostics = createDiagnosticCollection();
48574
48579
  var suggestionDiagnostics = createDiagnosticCollection();
48575
48580
  var typeofType = createTypeofType();
@@ -67719,12 +67724,7 @@ function createTypeChecker(host) {
67719
67724
  callback(getTypeAtPosition(source, i), getTypeAtPosition(target, i));
67720
67725
  }
67721
67726
  if (targetRestType) {
67722
- callback(getRestTypeAtPosition(
67723
- source,
67724
- paramCount,
67725
- /*readonly*/
67726
- isConstTypeVariable(targetRestType)
67727
- ), targetRestType);
67727
+ callback(getRestTypeAtPosition(source, paramCount), targetRestType);
67728
67728
  }
67729
67729
  }
67730
67730
  function applyToReturnTypes(source, target, callback) {
@@ -70617,6 +70617,15 @@ function createTypeChecker(host) {
70617
70617
  return type;
70618
70618
  }
70619
70619
  const rightType = getTypeOfExpression(expr.right);
70620
+ const hasInstanceMethodType = getSymbolHasInstanceMethodOfObjectType(rightType);
70621
+ if (hasInstanceMethodType) {
70622
+ const syntheticCall = createSyntheticHasInstanceMethodCall(left, expr.right, type, hasInstanceMethodType);
70623
+ const signature = getEffectsSignature(syntheticCall);
70624
+ const predicate = signature && getTypePredicateOfSignature(signature);
70625
+ if (predicate && (predicate.kind === 0 /* This */ || predicate.kind === 1 /* Identifier */)) {
70626
+ return narrowTypeByTypePredicate(type, predicate, syntheticCall, assumeTrue);
70627
+ }
70628
+ }
70620
70629
  if (!isTypeDerivedFrom(rightType, globalFunctionType)) {
70621
70630
  return type;
70622
70631
  }
@@ -70696,8 +70705,12 @@ function createTypeChecker(host) {
70696
70705
  }
70697
70706
  function narrowTypeByTypePredicate(type, predicate, callExpression, assumeTrue) {
70698
70707
  if (predicate.type && !(isTypeAny(type) && (predicate.type === globalObjectType || predicate.type === globalFunctionType))) {
70699
- const predicateArgument = getTypePredicateArgument(predicate, callExpression);
70708
+ let predicateArgument = getTypePredicateArgument(predicate, callExpression);
70700
70709
  if (predicateArgument) {
70710
+ if (isSyntheticExpression(predicateArgument) && predicate.parameterIndex === 0 && isSyntheticHasInstanceMethodCall(callExpression)) {
70711
+ Debug.assertNode(predicateArgument.parent, isExpression);
70712
+ predicateArgument = predicateArgument.parent;
70713
+ }
70701
70714
  if (isMatchingReference(reference, predicateArgument)) {
70702
70715
  return getNarrowedType(
70703
70716
  type,
@@ -75274,7 +75287,7 @@ function createTypeChecker(host) {
75274
75287
  }
75275
75288
  return createDiagnosticForNodeArray(getSourceFileOfNode(node), typeArguments, Diagnostics.Expected_0_type_arguments_but_got_1, belowArgCount === -Infinity ? aboveArgCount : belowArgCount, argCount);
75276
75289
  }
75277
- function resolveCall(node, signatures, candidatesOutArray, checkMode, callChainFlags, headMessage) {
75290
+ function resolveCall(node, signatures, candidatesOutArray, checkMode, callChainFlags, headMessageCallback) {
75278
75291
  const isTaggedTemplate = node.kind === 215 /* TaggedTemplateExpression */;
75279
75292
  const isDecorator2 = node.kind === 170 /* Decorator */;
75280
75293
  const isJsxOpeningOrSelfClosingElement = isJsxOpeningLikeElement(node);
@@ -75317,6 +75330,7 @@ function createTypeChecker(host) {
75317
75330
  chain = chainDiagnosticMessages(chain, Diagnostics.The_last_overload_gave_the_following_error);
75318
75331
  chain = chainDiagnosticMessages(chain, Diagnostics.No_overload_matches_this_call);
75319
75332
  }
75333
+ const headMessage = headMessageCallback == null ? void 0 : headMessageCallback();
75320
75334
  if (headMessage) {
75321
75335
  chain = chainDiagnosticMessages(chain, headMessage);
75322
75336
  }
@@ -75384,6 +75398,7 @@ function createTypeChecker(host) {
75384
75398
  map(diags, createDiagnosticMessageChainFromDiagnostic),
75385
75399
  Diagnostics.No_overload_matches_this_call
75386
75400
  );
75401
+ const headMessage = headMessageCallback == null ? void 0 : headMessageCallback();
75387
75402
  if (headMessage) {
75388
75403
  chain = chainDiagnosticMessages(chain, headMessage);
75389
75404
  }
@@ -75399,21 +75414,21 @@ function createTypeChecker(host) {
75399
75414
  diagnostics.add(diag2);
75400
75415
  }
75401
75416
  } else if (candidateForArgumentArityError) {
75402
- diagnostics.add(getArgumentArityError(node, [candidateForArgumentArityError], args, headMessage));
75417
+ diagnostics.add(getArgumentArityError(node, [candidateForArgumentArityError], args, headMessageCallback == null ? void 0 : headMessageCallback()));
75403
75418
  } else if (candidateForTypeArgumentError) {
75404
75419
  checkTypeArguments(
75405
75420
  candidateForTypeArgumentError,
75406
75421
  node.typeArguments,
75407
75422
  /*reportErrors*/
75408
75423
  true,
75409
- headMessage
75424
+ headMessageCallback == null ? void 0 : headMessageCallback()
75410
75425
  );
75411
75426
  } else {
75412
75427
  const signaturesWithCorrectTypeArgumentArity = filter(signatures, (s) => hasCorrectTypeArgumentArity(s, typeArguments));
75413
75428
  if (signaturesWithCorrectTypeArgumentArity.length === 0) {
75414
- diagnostics.add(getTypeArgumentArityError(node, signatures, typeArguments, headMessage));
75429
+ diagnostics.add(getTypeArgumentArityError(node, signatures, typeArguments, headMessageCallback == null ? void 0 : headMessageCallback()));
75415
75430
  } else {
75416
- diagnostics.add(getArgumentArityError(node, signaturesWithCorrectTypeArgumentArity, args, headMessage));
75431
+ diagnostics.add(getArgumentArityError(node, signaturesWithCorrectTypeArgumentArity, args, headMessageCallback == null ? void 0 : headMessageCallback()));
75417
75432
  }
75418
75433
  }
75419
75434
  }
@@ -75721,7 +75736,7 @@ function createTypeChecker(host) {
75721
75736
  error2(node, Diagnostics.Value_of_type_0_is_not_callable_Did_you_mean_to_include_new, typeToString(funcType));
75722
75737
  return resolveErrorCall(node);
75723
75738
  }
75724
- return resolveCall(node, callSignatures, candidatesOutArray, checkMode, callChainFlags);
75739
+ return resolveCall(node, callSignatures, candidatesOutArray, checkMode, callChainFlags, () => isSyntheticHasInstanceMethodCall(node) ? 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 : void 0);
75725
75740
  }
75726
75741
  function isGenericFunctionReturningFunction(signature) {
75727
75742
  return !!(signature.typeParameters && isFunctionType(getReturnTypeOfSignature(signature)));
@@ -76018,7 +76033,7 @@ function createTypeChecker(host) {
76018
76033
  invocationErrorRecovery(apparentType, 0 /* Call */, diag2);
76019
76034
  return resolveErrorCall(node);
76020
76035
  }
76021
- return resolveCall(node, callSignatures, candidatesOutArray, checkMode, 0 /* None */, headMessage);
76036
+ return resolveCall(node, callSignatures, candidatesOutArray, checkMode, 0 /* None */, () => headMessage);
76022
76037
  }
76023
76038
  function createSignatureForJSXIntrinsic(node, result) {
76024
76039
  const namespace = getJsxNamespaceAt(node);
@@ -76829,7 +76844,7 @@ function createTypeChecker(host) {
76829
76844
  }
76830
76845
  return void 0;
76831
76846
  }
76832
- function getRestTypeAtPosition(source, pos, readonly) {
76847
+ function getRestTypeAtPosition(source, pos) {
76833
76848
  const parameterCount = getParameterCount(source);
76834
76849
  const minArgumentCount = getMinArgumentCount(source);
76835
76850
  const restType = getEffectiveRestType(source);
@@ -76852,7 +76867,13 @@ function createTypeChecker(host) {
76852
76867
  names.push(name);
76853
76868
  }
76854
76869
  }
76855
- return createTupleType(types, flags, readonly, length(names) === length(types) ? names : void 0);
76870
+ return createTupleType(
76871
+ types,
76872
+ flags,
76873
+ /*readonly*/
76874
+ false,
76875
+ length(names) === length(types) ? names : void 0
76876
+ );
76856
76877
  }
76857
76878
  function getParameterCount(signature) {
76858
76879
  const length2 = signature.parameters.length;
@@ -78045,6 +78066,32 @@ function createTypeChecker(host) {
78045
78066
  function isConstEnumSymbol(symbol) {
78046
78067
  return (symbol.flags & 128 /* ConstEnum */) !== 0;
78047
78068
  }
78069
+ function getSymbolHasInstanceMethodOfObjectType(type) {
78070
+ const hasInstancePropertyName = getPropertyNameForKnownSymbolName("hasInstance");
78071
+ const hasInstanceProperty = getPropertyOfObjectType(type, hasInstancePropertyName);
78072
+ if (hasInstanceProperty) {
78073
+ const hasInstancePropertyType = getTypeOfSymbol(hasInstanceProperty);
78074
+ if (hasInstancePropertyType && getSignaturesOfType(hasInstancePropertyType, 0 /* Call */).length !== 0) {
78075
+ return hasInstancePropertyType;
78076
+ }
78077
+ }
78078
+ }
78079
+ function createSyntheticHasInstanceMethodCall(left, right, leftType, hasInstanceMethodType) {
78080
+ const syntheticExpression = createSyntheticExpression(right, hasInstanceMethodType);
78081
+ const syntheticArgument = createSyntheticExpression(left, leftType);
78082
+ const syntheticCall = parseNodeFactory.createCallExpression(
78083
+ syntheticExpression,
78084
+ /*typeArguments*/
78085
+ void 0,
78086
+ [syntheticArgument]
78087
+ );
78088
+ setParent(syntheticCall, left.parent);
78089
+ setTextRange(syntheticCall, left.parent);
78090
+ return syntheticCall;
78091
+ }
78092
+ function isSyntheticHasInstanceMethodCall(node) {
78093
+ return isSyntheticExpression(node.expression) && node.arguments.length === 1 && isSyntheticExpression(node.arguments[0]) && isBinaryExpression(node.parent) && node.parent.operatorToken.kind === 104 /* InstanceOfKeyword */ && node.parent.right === node.expression.parent && node.parent.left === node.arguments[0].parent;
78094
+ }
78048
78095
  function checkInstanceOfExpression(left, right, leftType, rightType) {
78049
78096
  if (leftType === silentNeverType || rightType === silentNeverType) {
78050
78097
  return silentNeverType;
@@ -78052,8 +78099,31 @@ function createTypeChecker(host) {
78052
78099
  if (!isTypeAny(leftType) && allTypesAssignableToKind(leftType, 402784252 /* Primitive */)) {
78053
78100
  error2(left, Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter);
78054
78101
  }
78055
- if (!(isTypeAny(rightType) || typeHasCallOrConstructSignatures(rightType) || isTypeSubtypeOf(rightType, globalFunctionType))) {
78056
- error2(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);
78102
+ if (!isTypeAny(rightType)) {
78103
+ const hasInstanceMethodType = getSymbolHasInstanceMethodOfObjectType(rightType);
78104
+ if (hasInstanceMethodType) {
78105
+ const cache = hasInstanceMethodType;
78106
+ if (cache.hasSimpleUnrestrictedSingleCallSignature === void 0) {
78107
+ const signature = getSingleCallSignature(hasInstanceMethodType);
78108
+ cache.hasSimpleUnrestrictedSingleCallSignature = !!signature && signature.parameters.length === 1 && !!(getTypeOfSymbol(signature.parameters[0]).flags & 3 /* AnyOrUnknown */) && !!signature.resolvedReturnType && !!(signature.resolvedReturnType.flags & 16 /* Boolean */);
78109
+ }
78110
+ if (!cache.hasSimpleUnrestrictedSingleCallSignature) {
78111
+ const syntheticCall = createSyntheticHasInstanceMethodCall(left, right, leftType, hasInstanceMethodType);
78112
+ const returnType = getReturnTypeOfSignature(getResolvedSignature(syntheticCall));
78113
+ 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);
78114
+ }
78115
+ }
78116
+ if (!(hasInstanceMethodType || typeHasCallOrConstructSignatures(rightType) || isTypeSubtypeOf(rightType, globalFunctionType))) {
78117
+ if (hasGlobalSymbolHasInstanceProperty === void 0) {
78118
+ const globalESSymbolConstructorSymbol = getGlobalESSymbolConstructorTypeSymbol(
78119
+ /*reportErrors*/
78120
+ false
78121
+ );
78122
+ hasGlobalSymbolHasInstanceProperty = !!globalESSymbolConstructorSymbol && getMembersOfSymbol(globalESSymbolConstructorSymbol).has("hasInstance");
78123
+ }
78124
+ const message = hasGlobalSymbolHasInstanceProperty ? Diagnostics.The_right_hand_side_of_an_instanceof_expression_must_be_either_of_type_any_an_object_type_with_a_Symbol_hasInstance_method_or_a_type_assignable_to_the_Function_interface_type : Diagnostics.The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type;
78125
+ error2(right, message);
78126
+ }
78057
78127
  }
78058
78128
  return booleanType;
78059
78129
  }
@@ -5139,7 +5139,7 @@ declare namespace ts {
5139
5139
  readonly asteriskToken?: AsteriskToken;
5140
5140
  readonly expression?: Expression;
5141
5141
  }
5142
- interface SyntheticExpression extends Expression {
5142
+ interface SyntheticExpression extends LeftHandSideExpression {
5143
5143
  readonly kind: SyntaxKind.SyntheticExpression;
5144
5144
  readonly isSpread: boolean;
5145
5145
  readonly type: Type;
@@ -7972,6 +7972,9 @@ ${lanes.join("\n")}
7972
7972
  await_using_statements_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules: diag(2852, 1 /* Error */, "await_using_statements_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules_2852", "'await using' statements are only allowed within async functions and at the top levels of modules."),
7973
7973
  await_using_statements_are_only_allowed_at_the_top_level_of_a_file_when_that_file_is_a_module_but_this_file_has_no_imports_or_exports_Consider_adding_an_empty_export_to_make_this_file_a_module: diag(2853, 1 /* Error */, "await_using_statements_are_only_allowed_at_the_top_level_of_a_file_when_that_file_is_a_module_but_th_2853", "'await using' statements are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module."),
7974
7974
  Top_level_await_using_statements_are_only_allowed_when_the_module_option_is_set_to_es2022_esnext_system_node16_or_nodenext_and_the_target_option_is_set_to_es2017_or_higher: diag(2854, 1 /* Error */, "Top_level_await_using_statements_are_only_allowed_when_the_module_option_is_set_to_es2022_esnext_sys_2854", "Top-level 'await using' statements are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', or 'nodenext', and the 'target' option is set to 'es2017' or higher."),
7975
+ 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(2855, 1 /* Error */, "The_left_hand_side_of_an_instanceof_expression_must_be_assignable_to_the_first_argument_of_the_right_2855", "The left-hand side of an 'instanceof' expression must be assignable to the first argument of the right-hand side's '[Symbol.hasInstance]' method."),
7976
+ 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(2856, 1 /* Error */, "An_object_s_Symbol_hasInstance_method_must_return_a_boolean_value_for_it_to_be_used_on_the_right_han_2856", "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."),
7977
+ The_right_hand_side_of_an_instanceof_expression_must_be_either_of_type_any_an_object_type_with_a_Symbol_hasInstance_method_or_a_type_assignable_to_the_Function_interface_type: diag(2857, 1 /* Error */, "The_right_hand_side_of_an_instanceof_expression_must_be_either_of_type_any_an_object_type_with_a_Sym_2857", "The right-hand side of an 'instanceof' expression must be either of type 'any', an object type with a '[Symbol.hasInstance]()' method, or a type assignable to the 'Function' interface type."),
7975
7978
  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}'."),
7976
7979
  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}'."),
7977
7980
  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}'."),
@@ -12452,6 +12455,7 @@ ${lanes.join("\n")}
12452
12455
  case 236 /* MetaProperty */:
12453
12456
  case 102 /* ImportKeyword */:
12454
12457
  case 282 /* MissingDeclaration */:
12458
+ case 237 /* SyntheticExpression */:
12455
12459
  return true;
12456
12460
  default:
12457
12461
  return false;
@@ -46337,6 +46341,7 @@ ${lanes.join("\n")}
46337
46341
  var potentialReflectCollisions = [];
46338
46342
  var potentialUnusedRenamedBindingElementsInTypes = [];
46339
46343
  var awaitedTypeStack = [];
46344
+ var hasGlobalSymbolHasInstanceProperty;
46340
46345
  var diagnostics = createDiagnosticCollection();
46341
46346
  var suggestionDiagnostics = createDiagnosticCollection();
46342
46347
  var typeofType = createTypeofType();
@@ -65486,12 +65491,7 @@ ${lanes.join("\n")}
65486
65491
  callback(getTypeAtPosition(source, i), getTypeAtPosition(target, i));
65487
65492
  }
65488
65493
  if (targetRestType) {
65489
- callback(getRestTypeAtPosition(
65490
- source,
65491
- paramCount,
65492
- /*readonly*/
65493
- isConstTypeVariable(targetRestType)
65494
- ), targetRestType);
65494
+ callback(getRestTypeAtPosition(source, paramCount), targetRestType);
65495
65495
  }
65496
65496
  }
65497
65497
  function applyToReturnTypes(source, target, callback) {
@@ -68384,6 +68384,15 @@ ${lanes.join("\n")}
68384
68384
  return type;
68385
68385
  }
68386
68386
  const rightType = getTypeOfExpression(expr.right);
68387
+ const hasInstanceMethodType = getSymbolHasInstanceMethodOfObjectType(rightType);
68388
+ if (hasInstanceMethodType) {
68389
+ const syntheticCall = createSyntheticHasInstanceMethodCall(left, expr.right, type, hasInstanceMethodType);
68390
+ const signature = getEffectsSignature(syntheticCall);
68391
+ const predicate = signature && getTypePredicateOfSignature(signature);
68392
+ if (predicate && (predicate.kind === 0 /* This */ || predicate.kind === 1 /* Identifier */)) {
68393
+ return narrowTypeByTypePredicate(type, predicate, syntheticCall, assumeTrue);
68394
+ }
68395
+ }
68387
68396
  if (!isTypeDerivedFrom(rightType, globalFunctionType)) {
68388
68397
  return type;
68389
68398
  }
@@ -68463,8 +68472,12 @@ ${lanes.join("\n")}
68463
68472
  }
68464
68473
  function narrowTypeByTypePredicate(type, predicate, callExpression, assumeTrue) {
68465
68474
  if (predicate.type && !(isTypeAny(type) && (predicate.type === globalObjectType || predicate.type === globalFunctionType))) {
68466
- const predicateArgument = getTypePredicateArgument(predicate, callExpression);
68475
+ let predicateArgument = getTypePredicateArgument(predicate, callExpression);
68467
68476
  if (predicateArgument) {
68477
+ if (isSyntheticExpression(predicateArgument) && predicate.parameterIndex === 0 && isSyntheticHasInstanceMethodCall(callExpression)) {
68478
+ Debug.assertNode(predicateArgument.parent, isExpression);
68479
+ predicateArgument = predicateArgument.parent;
68480
+ }
68468
68481
  if (isMatchingReference(reference, predicateArgument)) {
68469
68482
  return getNarrowedType(
68470
68483
  type,
@@ -73041,7 +73054,7 @@ ${lanes.join("\n")}
73041
73054
  }
73042
73055
  return createDiagnosticForNodeArray(getSourceFileOfNode(node), typeArguments, Diagnostics.Expected_0_type_arguments_but_got_1, belowArgCount === -Infinity ? aboveArgCount : belowArgCount, argCount);
73043
73056
  }
73044
- function resolveCall(node, signatures, candidatesOutArray, checkMode, callChainFlags, headMessage) {
73057
+ function resolveCall(node, signatures, candidatesOutArray, checkMode, callChainFlags, headMessageCallback) {
73045
73058
  const isTaggedTemplate = node.kind === 215 /* TaggedTemplateExpression */;
73046
73059
  const isDecorator2 = node.kind === 170 /* Decorator */;
73047
73060
  const isJsxOpeningOrSelfClosingElement = isJsxOpeningLikeElement(node);
@@ -73084,6 +73097,7 @@ ${lanes.join("\n")}
73084
73097
  chain = chainDiagnosticMessages(chain, Diagnostics.The_last_overload_gave_the_following_error);
73085
73098
  chain = chainDiagnosticMessages(chain, Diagnostics.No_overload_matches_this_call);
73086
73099
  }
73100
+ const headMessage = headMessageCallback == null ? void 0 : headMessageCallback();
73087
73101
  if (headMessage) {
73088
73102
  chain = chainDiagnosticMessages(chain, headMessage);
73089
73103
  }
@@ -73151,6 +73165,7 @@ ${lanes.join("\n")}
73151
73165
  map(diags, createDiagnosticMessageChainFromDiagnostic),
73152
73166
  Diagnostics.No_overload_matches_this_call
73153
73167
  );
73168
+ const headMessage = headMessageCallback == null ? void 0 : headMessageCallback();
73154
73169
  if (headMessage) {
73155
73170
  chain = chainDiagnosticMessages(chain, headMessage);
73156
73171
  }
@@ -73166,21 +73181,21 @@ ${lanes.join("\n")}
73166
73181
  diagnostics.add(diag2);
73167
73182
  }
73168
73183
  } else if (candidateForArgumentArityError) {
73169
- diagnostics.add(getArgumentArityError(node, [candidateForArgumentArityError], args, headMessage));
73184
+ diagnostics.add(getArgumentArityError(node, [candidateForArgumentArityError], args, headMessageCallback == null ? void 0 : headMessageCallback()));
73170
73185
  } else if (candidateForTypeArgumentError) {
73171
73186
  checkTypeArguments(
73172
73187
  candidateForTypeArgumentError,
73173
73188
  node.typeArguments,
73174
73189
  /*reportErrors*/
73175
73190
  true,
73176
- headMessage
73191
+ headMessageCallback == null ? void 0 : headMessageCallback()
73177
73192
  );
73178
73193
  } else {
73179
73194
  const signaturesWithCorrectTypeArgumentArity = filter(signatures, (s) => hasCorrectTypeArgumentArity(s, typeArguments));
73180
73195
  if (signaturesWithCorrectTypeArgumentArity.length === 0) {
73181
- diagnostics.add(getTypeArgumentArityError(node, signatures, typeArguments, headMessage));
73196
+ diagnostics.add(getTypeArgumentArityError(node, signatures, typeArguments, headMessageCallback == null ? void 0 : headMessageCallback()));
73182
73197
  } else {
73183
- diagnostics.add(getArgumentArityError(node, signaturesWithCorrectTypeArgumentArity, args, headMessage));
73198
+ diagnostics.add(getArgumentArityError(node, signaturesWithCorrectTypeArgumentArity, args, headMessageCallback == null ? void 0 : headMessageCallback()));
73184
73199
  }
73185
73200
  }
73186
73201
  }
@@ -73488,7 +73503,7 @@ ${lanes.join("\n")}
73488
73503
  error2(node, Diagnostics.Value_of_type_0_is_not_callable_Did_you_mean_to_include_new, typeToString(funcType));
73489
73504
  return resolveErrorCall(node);
73490
73505
  }
73491
- return resolveCall(node, callSignatures, candidatesOutArray, checkMode, callChainFlags);
73506
+ return resolveCall(node, callSignatures, candidatesOutArray, checkMode, callChainFlags, () => isSyntheticHasInstanceMethodCall(node) ? 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 : void 0);
73492
73507
  }
73493
73508
  function isGenericFunctionReturningFunction(signature) {
73494
73509
  return !!(signature.typeParameters && isFunctionType(getReturnTypeOfSignature(signature)));
@@ -73785,7 +73800,7 @@ ${lanes.join("\n")}
73785
73800
  invocationErrorRecovery(apparentType, 0 /* Call */, diag2);
73786
73801
  return resolveErrorCall(node);
73787
73802
  }
73788
- return resolveCall(node, callSignatures, candidatesOutArray, checkMode, 0 /* None */, headMessage);
73803
+ return resolveCall(node, callSignatures, candidatesOutArray, checkMode, 0 /* None */, () => headMessage);
73789
73804
  }
73790
73805
  function createSignatureForJSXIntrinsic(node, result) {
73791
73806
  const namespace = getJsxNamespaceAt(node);
@@ -74596,7 +74611,7 @@ ${lanes.join("\n")}
74596
74611
  }
74597
74612
  return void 0;
74598
74613
  }
74599
- function getRestTypeAtPosition(source, pos, readonly) {
74614
+ function getRestTypeAtPosition(source, pos) {
74600
74615
  const parameterCount = getParameterCount(source);
74601
74616
  const minArgumentCount = getMinArgumentCount(source);
74602
74617
  const restType = getEffectiveRestType(source);
@@ -74619,7 +74634,13 @@ ${lanes.join("\n")}
74619
74634
  names.push(name);
74620
74635
  }
74621
74636
  }
74622
- return createTupleType(types, flags, readonly, length(names) === length(types) ? names : void 0);
74637
+ return createTupleType(
74638
+ types,
74639
+ flags,
74640
+ /*readonly*/
74641
+ false,
74642
+ length(names) === length(types) ? names : void 0
74643
+ );
74623
74644
  }
74624
74645
  function getParameterCount(signature) {
74625
74646
  const length2 = signature.parameters.length;
@@ -75812,6 +75833,32 @@ ${lanes.join("\n")}
75812
75833
  function isConstEnumSymbol(symbol) {
75813
75834
  return (symbol.flags & 128 /* ConstEnum */) !== 0;
75814
75835
  }
75836
+ function getSymbolHasInstanceMethodOfObjectType(type) {
75837
+ const hasInstancePropertyName = getPropertyNameForKnownSymbolName("hasInstance");
75838
+ const hasInstanceProperty = getPropertyOfObjectType(type, hasInstancePropertyName);
75839
+ if (hasInstanceProperty) {
75840
+ const hasInstancePropertyType = getTypeOfSymbol(hasInstanceProperty);
75841
+ if (hasInstancePropertyType && getSignaturesOfType(hasInstancePropertyType, 0 /* Call */).length !== 0) {
75842
+ return hasInstancePropertyType;
75843
+ }
75844
+ }
75845
+ }
75846
+ function createSyntheticHasInstanceMethodCall(left, right, leftType, hasInstanceMethodType) {
75847
+ const syntheticExpression = createSyntheticExpression(right, hasInstanceMethodType);
75848
+ const syntheticArgument = createSyntheticExpression(left, leftType);
75849
+ const syntheticCall = parseNodeFactory.createCallExpression(
75850
+ syntheticExpression,
75851
+ /*typeArguments*/
75852
+ void 0,
75853
+ [syntheticArgument]
75854
+ );
75855
+ setParent(syntheticCall, left.parent);
75856
+ setTextRange(syntheticCall, left.parent);
75857
+ return syntheticCall;
75858
+ }
75859
+ function isSyntheticHasInstanceMethodCall(node) {
75860
+ return isSyntheticExpression(node.expression) && node.arguments.length === 1 && isSyntheticExpression(node.arguments[0]) && isBinaryExpression(node.parent) && node.parent.operatorToken.kind === 104 /* InstanceOfKeyword */ && node.parent.right === node.expression.parent && node.parent.left === node.arguments[0].parent;
75861
+ }
75815
75862
  function checkInstanceOfExpression(left, right, leftType, rightType) {
75816
75863
  if (leftType === silentNeverType || rightType === silentNeverType) {
75817
75864
  return silentNeverType;
@@ -75819,8 +75866,31 @@ ${lanes.join("\n")}
75819
75866
  if (!isTypeAny(leftType) && allTypesAssignableToKind(leftType, 402784252 /* Primitive */)) {
75820
75867
  error2(left, Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter);
75821
75868
  }
75822
- if (!(isTypeAny(rightType) || typeHasCallOrConstructSignatures(rightType) || isTypeSubtypeOf(rightType, globalFunctionType))) {
75823
- error2(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);
75869
+ if (!isTypeAny(rightType)) {
75870
+ const hasInstanceMethodType = getSymbolHasInstanceMethodOfObjectType(rightType);
75871
+ if (hasInstanceMethodType) {
75872
+ const cache = hasInstanceMethodType;
75873
+ if (cache.hasSimpleUnrestrictedSingleCallSignature === void 0) {
75874
+ const signature = getSingleCallSignature(hasInstanceMethodType);
75875
+ cache.hasSimpleUnrestrictedSingleCallSignature = !!signature && signature.parameters.length === 1 && !!(getTypeOfSymbol(signature.parameters[0]).flags & 3 /* AnyOrUnknown */) && !!signature.resolvedReturnType && !!(signature.resolvedReturnType.flags & 16 /* Boolean */);
75876
+ }
75877
+ if (!cache.hasSimpleUnrestrictedSingleCallSignature) {
75878
+ const syntheticCall = createSyntheticHasInstanceMethodCall(left, right, leftType, hasInstanceMethodType);
75879
+ const returnType = getReturnTypeOfSignature(getResolvedSignature(syntheticCall));
75880
+ 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);
75881
+ }
75882
+ }
75883
+ if (!(hasInstanceMethodType || typeHasCallOrConstructSignatures(rightType) || isTypeSubtypeOf(rightType, globalFunctionType))) {
75884
+ if (hasGlobalSymbolHasInstanceProperty === void 0) {
75885
+ const globalESSymbolConstructorSymbol = getGlobalESSymbolConstructorTypeSymbol(
75886
+ /*reportErrors*/
75887
+ false
75888
+ );
75889
+ hasGlobalSymbolHasInstanceProperty = !!globalESSymbolConstructorSymbol && getMembersOfSymbol(globalESSymbolConstructorSymbol).has("hasInstance");
75890
+ }
75891
+ const message = hasGlobalSymbolHasInstanceProperty ? Diagnostics.The_right_hand_side_of_an_instanceof_expression_must_be_either_of_type_any_an_object_type_with_a_Symbol_hasInstance_method_or_a_type_assignable_to_the_Function_interface_type : Diagnostics.The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type;
75892
+ error2(right, message);
75893
+ }
75824
75894
  }
75825
75895
  return booleanType;
75826
75896
  }
@@ -1086,7 +1086,7 @@ declare namespace ts {
1086
1086
  readonly asteriskToken?: AsteriskToken;
1087
1087
  readonly expression?: Expression;
1088
1088
  }
1089
- interface SyntheticExpression extends Expression {
1089
+ interface SyntheticExpression extends LeftHandSideExpression {
1090
1090
  readonly kind: SyntaxKind.SyntheticExpression;
1091
1091
  readonly isSpread: boolean;
1092
1092
  readonly type: Type;
package/lib/typescript.js CHANGED
@@ -7972,6 +7972,9 @@ ${lanes.join("\n")}
7972
7972
  await_using_statements_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules: diag(2852, 1 /* Error */, "await_using_statements_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules_2852", "'await using' statements are only allowed within async functions and at the top levels of modules."),
7973
7973
  await_using_statements_are_only_allowed_at_the_top_level_of_a_file_when_that_file_is_a_module_but_this_file_has_no_imports_or_exports_Consider_adding_an_empty_export_to_make_this_file_a_module: diag(2853, 1 /* Error */, "await_using_statements_are_only_allowed_at_the_top_level_of_a_file_when_that_file_is_a_module_but_th_2853", "'await using' statements are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module."),
7974
7974
  Top_level_await_using_statements_are_only_allowed_when_the_module_option_is_set_to_es2022_esnext_system_node16_or_nodenext_and_the_target_option_is_set_to_es2017_or_higher: diag(2854, 1 /* Error */, "Top_level_await_using_statements_are_only_allowed_when_the_module_option_is_set_to_es2022_esnext_sys_2854", "Top-level 'await using' statements are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', or 'nodenext', and the 'target' option is set to 'es2017' or higher."),
7975
+ 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(2855, 1 /* Error */, "The_left_hand_side_of_an_instanceof_expression_must_be_assignable_to_the_first_argument_of_the_right_2855", "The left-hand side of an 'instanceof' expression must be assignable to the first argument of the right-hand side's '[Symbol.hasInstance]' method."),
7976
+ 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(2856, 1 /* Error */, "An_object_s_Symbol_hasInstance_method_must_return_a_boolean_value_for_it_to_be_used_on_the_right_han_2856", "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."),
7977
+ The_right_hand_side_of_an_instanceof_expression_must_be_either_of_type_any_an_object_type_with_a_Symbol_hasInstance_method_or_a_type_assignable_to_the_Function_interface_type: diag(2857, 1 /* Error */, "The_right_hand_side_of_an_instanceof_expression_must_be_either_of_type_any_an_object_type_with_a_Sym_2857", "The right-hand side of an 'instanceof' expression must be either of type 'any', an object type with a '[Symbol.hasInstance]()' method, or a type assignable to the 'Function' interface type."),
7975
7978
  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}'."),
7976
7979
  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}'."),
7977
7980
  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}'."),
@@ -12452,6 +12455,7 @@ ${lanes.join("\n")}
12452
12455
  case 236 /* MetaProperty */:
12453
12456
  case 102 /* ImportKeyword */:
12454
12457
  case 282 /* MissingDeclaration */:
12458
+ case 237 /* SyntheticExpression */:
12455
12459
  return true;
12456
12460
  default:
12457
12461
  return false;
@@ -46337,6 +46341,7 @@ ${lanes.join("\n")}
46337
46341
  var potentialReflectCollisions = [];
46338
46342
  var potentialUnusedRenamedBindingElementsInTypes = [];
46339
46343
  var awaitedTypeStack = [];
46344
+ var hasGlobalSymbolHasInstanceProperty;
46340
46345
  var diagnostics = createDiagnosticCollection();
46341
46346
  var suggestionDiagnostics = createDiagnosticCollection();
46342
46347
  var typeofType = createTypeofType();
@@ -65486,12 +65491,7 @@ ${lanes.join("\n")}
65486
65491
  callback(getTypeAtPosition(source, i), getTypeAtPosition(target, i));
65487
65492
  }
65488
65493
  if (targetRestType) {
65489
- callback(getRestTypeAtPosition(
65490
- source,
65491
- paramCount,
65492
- /*readonly*/
65493
- isConstTypeVariable(targetRestType)
65494
- ), targetRestType);
65494
+ callback(getRestTypeAtPosition(source, paramCount), targetRestType);
65495
65495
  }
65496
65496
  }
65497
65497
  function applyToReturnTypes(source, target, callback) {
@@ -68384,6 +68384,15 @@ ${lanes.join("\n")}
68384
68384
  return type;
68385
68385
  }
68386
68386
  const rightType = getTypeOfExpression(expr.right);
68387
+ const hasInstanceMethodType = getSymbolHasInstanceMethodOfObjectType(rightType);
68388
+ if (hasInstanceMethodType) {
68389
+ const syntheticCall = createSyntheticHasInstanceMethodCall(left, expr.right, type, hasInstanceMethodType);
68390
+ const signature = getEffectsSignature(syntheticCall);
68391
+ const predicate = signature && getTypePredicateOfSignature(signature);
68392
+ if (predicate && (predicate.kind === 0 /* This */ || predicate.kind === 1 /* Identifier */)) {
68393
+ return narrowTypeByTypePredicate(type, predicate, syntheticCall, assumeTrue);
68394
+ }
68395
+ }
68387
68396
  if (!isTypeDerivedFrom(rightType, globalFunctionType)) {
68388
68397
  return type;
68389
68398
  }
@@ -68463,8 +68472,12 @@ ${lanes.join("\n")}
68463
68472
  }
68464
68473
  function narrowTypeByTypePredicate(type, predicate, callExpression, assumeTrue) {
68465
68474
  if (predicate.type && !(isTypeAny(type) && (predicate.type === globalObjectType || predicate.type === globalFunctionType))) {
68466
- const predicateArgument = getTypePredicateArgument(predicate, callExpression);
68475
+ let predicateArgument = getTypePredicateArgument(predicate, callExpression);
68467
68476
  if (predicateArgument) {
68477
+ if (isSyntheticExpression(predicateArgument) && predicate.parameterIndex === 0 && isSyntheticHasInstanceMethodCall(callExpression)) {
68478
+ Debug.assertNode(predicateArgument.parent, isExpression);
68479
+ predicateArgument = predicateArgument.parent;
68480
+ }
68468
68481
  if (isMatchingReference(reference, predicateArgument)) {
68469
68482
  return getNarrowedType(
68470
68483
  type,
@@ -73041,7 +73054,7 @@ ${lanes.join("\n")}
73041
73054
  }
73042
73055
  return createDiagnosticForNodeArray(getSourceFileOfNode(node), typeArguments, Diagnostics.Expected_0_type_arguments_but_got_1, belowArgCount === -Infinity ? aboveArgCount : belowArgCount, argCount);
73043
73056
  }
73044
- function resolveCall(node, signatures, candidatesOutArray, checkMode, callChainFlags, headMessage) {
73057
+ function resolveCall(node, signatures, candidatesOutArray, checkMode, callChainFlags, headMessageCallback) {
73045
73058
  const isTaggedTemplate = node.kind === 215 /* TaggedTemplateExpression */;
73046
73059
  const isDecorator2 = node.kind === 170 /* Decorator */;
73047
73060
  const isJsxOpeningOrSelfClosingElement = isJsxOpeningLikeElement(node);
@@ -73084,6 +73097,7 @@ ${lanes.join("\n")}
73084
73097
  chain = chainDiagnosticMessages(chain, Diagnostics.The_last_overload_gave_the_following_error);
73085
73098
  chain = chainDiagnosticMessages(chain, Diagnostics.No_overload_matches_this_call);
73086
73099
  }
73100
+ const headMessage = headMessageCallback == null ? void 0 : headMessageCallback();
73087
73101
  if (headMessage) {
73088
73102
  chain = chainDiagnosticMessages(chain, headMessage);
73089
73103
  }
@@ -73151,6 +73165,7 @@ ${lanes.join("\n")}
73151
73165
  map(diags, createDiagnosticMessageChainFromDiagnostic),
73152
73166
  Diagnostics.No_overload_matches_this_call
73153
73167
  );
73168
+ const headMessage = headMessageCallback == null ? void 0 : headMessageCallback();
73154
73169
  if (headMessage) {
73155
73170
  chain = chainDiagnosticMessages(chain, headMessage);
73156
73171
  }
@@ -73166,21 +73181,21 @@ ${lanes.join("\n")}
73166
73181
  diagnostics.add(diag2);
73167
73182
  }
73168
73183
  } else if (candidateForArgumentArityError) {
73169
- diagnostics.add(getArgumentArityError(node, [candidateForArgumentArityError], args, headMessage));
73184
+ diagnostics.add(getArgumentArityError(node, [candidateForArgumentArityError], args, headMessageCallback == null ? void 0 : headMessageCallback()));
73170
73185
  } else if (candidateForTypeArgumentError) {
73171
73186
  checkTypeArguments(
73172
73187
  candidateForTypeArgumentError,
73173
73188
  node.typeArguments,
73174
73189
  /*reportErrors*/
73175
73190
  true,
73176
- headMessage
73191
+ headMessageCallback == null ? void 0 : headMessageCallback()
73177
73192
  );
73178
73193
  } else {
73179
73194
  const signaturesWithCorrectTypeArgumentArity = filter(signatures, (s) => hasCorrectTypeArgumentArity(s, typeArguments));
73180
73195
  if (signaturesWithCorrectTypeArgumentArity.length === 0) {
73181
- diagnostics.add(getTypeArgumentArityError(node, signatures, typeArguments, headMessage));
73196
+ diagnostics.add(getTypeArgumentArityError(node, signatures, typeArguments, headMessageCallback == null ? void 0 : headMessageCallback()));
73182
73197
  } else {
73183
- diagnostics.add(getArgumentArityError(node, signaturesWithCorrectTypeArgumentArity, args, headMessage));
73198
+ diagnostics.add(getArgumentArityError(node, signaturesWithCorrectTypeArgumentArity, args, headMessageCallback == null ? void 0 : headMessageCallback()));
73184
73199
  }
73185
73200
  }
73186
73201
  }
@@ -73488,7 +73503,7 @@ ${lanes.join("\n")}
73488
73503
  error2(node, Diagnostics.Value_of_type_0_is_not_callable_Did_you_mean_to_include_new, typeToString(funcType));
73489
73504
  return resolveErrorCall(node);
73490
73505
  }
73491
- return resolveCall(node, callSignatures, candidatesOutArray, checkMode, callChainFlags);
73506
+ return resolveCall(node, callSignatures, candidatesOutArray, checkMode, callChainFlags, () => isSyntheticHasInstanceMethodCall(node) ? 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 : void 0);
73492
73507
  }
73493
73508
  function isGenericFunctionReturningFunction(signature) {
73494
73509
  return !!(signature.typeParameters && isFunctionType(getReturnTypeOfSignature(signature)));
@@ -73785,7 +73800,7 @@ ${lanes.join("\n")}
73785
73800
  invocationErrorRecovery(apparentType, 0 /* Call */, diag2);
73786
73801
  return resolveErrorCall(node);
73787
73802
  }
73788
- return resolveCall(node, callSignatures, candidatesOutArray, checkMode, 0 /* None */, headMessage);
73803
+ return resolveCall(node, callSignatures, candidatesOutArray, checkMode, 0 /* None */, () => headMessage);
73789
73804
  }
73790
73805
  function createSignatureForJSXIntrinsic(node, result) {
73791
73806
  const namespace = getJsxNamespaceAt(node);
@@ -74596,7 +74611,7 @@ ${lanes.join("\n")}
74596
74611
  }
74597
74612
  return void 0;
74598
74613
  }
74599
- function getRestTypeAtPosition(source, pos, readonly) {
74614
+ function getRestTypeAtPosition(source, pos) {
74600
74615
  const parameterCount = getParameterCount(source);
74601
74616
  const minArgumentCount = getMinArgumentCount(source);
74602
74617
  const restType = getEffectiveRestType(source);
@@ -74619,7 +74634,13 @@ ${lanes.join("\n")}
74619
74634
  names.push(name);
74620
74635
  }
74621
74636
  }
74622
- return createTupleType(types, flags, readonly, length(names) === length(types) ? names : void 0);
74637
+ return createTupleType(
74638
+ types,
74639
+ flags,
74640
+ /*readonly*/
74641
+ false,
74642
+ length(names) === length(types) ? names : void 0
74643
+ );
74623
74644
  }
74624
74645
  function getParameterCount(signature) {
74625
74646
  const length2 = signature.parameters.length;
@@ -75812,6 +75833,32 @@ ${lanes.join("\n")}
75812
75833
  function isConstEnumSymbol(symbol) {
75813
75834
  return (symbol.flags & 128 /* ConstEnum */) !== 0;
75814
75835
  }
75836
+ function getSymbolHasInstanceMethodOfObjectType(type) {
75837
+ const hasInstancePropertyName = getPropertyNameForKnownSymbolName("hasInstance");
75838
+ const hasInstanceProperty = getPropertyOfObjectType(type, hasInstancePropertyName);
75839
+ if (hasInstanceProperty) {
75840
+ const hasInstancePropertyType = getTypeOfSymbol(hasInstanceProperty);
75841
+ if (hasInstancePropertyType && getSignaturesOfType(hasInstancePropertyType, 0 /* Call */).length !== 0) {
75842
+ return hasInstancePropertyType;
75843
+ }
75844
+ }
75845
+ }
75846
+ function createSyntheticHasInstanceMethodCall(left, right, leftType, hasInstanceMethodType) {
75847
+ const syntheticExpression = createSyntheticExpression(right, hasInstanceMethodType);
75848
+ const syntheticArgument = createSyntheticExpression(left, leftType);
75849
+ const syntheticCall = parseNodeFactory.createCallExpression(
75850
+ syntheticExpression,
75851
+ /*typeArguments*/
75852
+ void 0,
75853
+ [syntheticArgument]
75854
+ );
75855
+ setParent(syntheticCall, left.parent);
75856
+ setTextRange(syntheticCall, left.parent);
75857
+ return syntheticCall;
75858
+ }
75859
+ function isSyntheticHasInstanceMethodCall(node) {
75860
+ return isSyntheticExpression(node.expression) && node.arguments.length === 1 && isSyntheticExpression(node.arguments[0]) && isBinaryExpression(node.parent) && node.parent.operatorToken.kind === 104 /* InstanceOfKeyword */ && node.parent.right === node.expression.parent && node.parent.left === node.arguments[0].parent;
75861
+ }
75815
75862
  function checkInstanceOfExpression(left, right, leftType, rightType) {
75816
75863
  if (leftType === silentNeverType || rightType === silentNeverType) {
75817
75864
  return silentNeverType;
@@ -75819,8 +75866,31 @@ ${lanes.join("\n")}
75819
75866
  if (!isTypeAny(leftType) && allTypesAssignableToKind(leftType, 402784252 /* Primitive */)) {
75820
75867
  error2(left, Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter);
75821
75868
  }
75822
- if (!(isTypeAny(rightType) || typeHasCallOrConstructSignatures(rightType) || isTypeSubtypeOf(rightType, globalFunctionType))) {
75823
- error2(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);
75869
+ if (!isTypeAny(rightType)) {
75870
+ const hasInstanceMethodType = getSymbolHasInstanceMethodOfObjectType(rightType);
75871
+ if (hasInstanceMethodType) {
75872
+ const cache = hasInstanceMethodType;
75873
+ if (cache.hasSimpleUnrestrictedSingleCallSignature === void 0) {
75874
+ const signature = getSingleCallSignature(hasInstanceMethodType);
75875
+ cache.hasSimpleUnrestrictedSingleCallSignature = !!signature && signature.parameters.length === 1 && !!(getTypeOfSymbol(signature.parameters[0]).flags & 3 /* AnyOrUnknown */) && !!signature.resolvedReturnType && !!(signature.resolvedReturnType.flags & 16 /* Boolean */);
75876
+ }
75877
+ if (!cache.hasSimpleUnrestrictedSingleCallSignature) {
75878
+ const syntheticCall = createSyntheticHasInstanceMethodCall(left, right, leftType, hasInstanceMethodType);
75879
+ const returnType = getReturnTypeOfSignature(getResolvedSignature(syntheticCall));
75880
+ 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);
75881
+ }
75882
+ }
75883
+ if (!(hasInstanceMethodType || typeHasCallOrConstructSignatures(rightType) || isTypeSubtypeOf(rightType, globalFunctionType))) {
75884
+ if (hasGlobalSymbolHasInstanceProperty === void 0) {
75885
+ const globalESSymbolConstructorSymbol = getGlobalESSymbolConstructorTypeSymbol(
75886
+ /*reportErrors*/
75887
+ false
75888
+ );
75889
+ hasGlobalSymbolHasInstanceProperty = !!globalESSymbolConstructorSymbol && getMembersOfSymbol(globalESSymbolConstructorSymbol).has("hasInstance");
75890
+ }
75891
+ const message = hasGlobalSymbolHasInstanceProperty ? Diagnostics.The_right_hand_side_of_an_instanceof_expression_must_be_either_of_type_any_an_object_type_with_a_Symbol_hasInstance_method_or_a_type_assignable_to_the_Function_interface_type : Diagnostics.The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type;
75892
+ error2(right, message);
75893
+ }
75824
75894
  }
75825
75895
  return booleanType;
75826
75896
  }
@@ -6042,6 +6042,9 @@ var Diagnostics = {
6042
6042
  await_using_statements_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules: diag(2852, 1 /* Error */, "await_using_statements_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules_2852", "'await using' statements are only allowed within async functions and at the top levels of modules."),
6043
6043
  await_using_statements_are_only_allowed_at_the_top_level_of_a_file_when_that_file_is_a_module_but_this_file_has_no_imports_or_exports_Consider_adding_an_empty_export_to_make_this_file_a_module: diag(2853, 1 /* Error */, "await_using_statements_are_only_allowed_at_the_top_level_of_a_file_when_that_file_is_a_module_but_th_2853", "'await using' statements are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module."),
6044
6044
  Top_level_await_using_statements_are_only_allowed_when_the_module_option_is_set_to_es2022_esnext_system_node16_or_nodenext_and_the_target_option_is_set_to_es2017_or_higher: diag(2854, 1 /* Error */, "Top_level_await_using_statements_are_only_allowed_when_the_module_option_is_set_to_es2022_esnext_sys_2854", "Top-level 'await using' statements are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', or 'nodenext', and the 'target' option is set to 'es2017' or higher."),
6045
+ 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(2855, 1 /* Error */, "The_left_hand_side_of_an_instanceof_expression_must_be_assignable_to_the_first_argument_of_the_right_2855", "The left-hand side of an 'instanceof' expression must be assignable to the first argument of the right-hand side's '[Symbol.hasInstance]' method."),
6046
+ 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(2856, 1 /* Error */, "An_object_s_Symbol_hasInstance_method_must_return_a_boolean_value_for_it_to_be_used_on_the_right_han_2856", "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."),
6047
+ The_right_hand_side_of_an_instanceof_expression_must_be_either_of_type_any_an_object_type_with_a_Symbol_hasInstance_method_or_a_type_assignable_to_the_Function_interface_type: diag(2857, 1 /* Error */, "The_right_hand_side_of_an_instanceof_expression_must_be_either_of_type_any_an_object_type_with_a_Sym_2857", "The right-hand side of an 'instanceof' expression must be either of type 'any', an object type with a '[Symbol.hasInstance]()' method, or a type assignable to the 'Function' interface type."),
6045
6048
  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}'."),
6046
6049
  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}'."),
6047
6050
  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}'."),
@@ -9871,6 +9874,7 @@ function isLeftHandSideExpressionKind(kind) {
9871
9874
  case 236 /* MetaProperty */:
9872
9875
  case 102 /* ImportKeyword */:
9873
9876
  case 282 /* MissingDeclaration */:
9877
+ case 237 /* SyntheticExpression */:
9874
9878
  return true;
9875
9879
  default:
9876
9880
  return false;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@typescript-deploys/pr-build",
3
3
  "author": "Microsoft Corp.",
4
4
  "homepage": "https://www.typescriptlang.org/",
5
- "version": "5.2.0-pr-55034-8",
5
+ "version": "5.2.0-pr-55052-3",
6
6
  "license": "Apache-2.0",
7
7
  "description": "TypeScript is a language for application scale JavaScript development",
8
8
  "keywords": [
@@ -114,5 +114,5 @@
114
114
  "node": "20.1.0",
115
115
  "npm": "8.19.4"
116
116
  },
117
- "gitHead": "2842e44bf3f80d0459b1687e4d236d03aa9a3b17"
117
+ "gitHead": "4c0125c23185bb0cba8a8f4397a0748662da3d8c"
118
118
  }