@@ -33791,7 +33791,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
33791
33791
return createDiagnosticForNodeArray(getSourceFileOfNode(node), typeArguments, Diagnostics.Expected_0_type_arguments_but_got_1, belowArgCount === -Infinity ? aboveArgCount : belowArgCount, argCount);
33792
33792
}
33793
33793
33794
- function resolveCall(node: CallLikeExpression, signatures: readonly Signature[], candidatesOutArray: Signature[] | undefined, checkMode: CheckMode, callChainFlags: SignatureFlags, headMessageCallback?: () => DiagnosticMessage | undefined): Signature {
33794
+ function resolveCall(node: CallLikeExpression, signatures: readonly Signature[], candidatesOutArray: Signature[] | undefined, checkMode: CheckMode, callChainFlags: SignatureFlags, headMessage?: DiagnosticMessage | undefined): Signature {
33795
33795
const isTaggedTemplate = node.kind === SyntaxKind.TaggedTemplateExpression;
33796
33796
const isDecorator = node.kind === SyntaxKind.Decorator;
33797
33797
const isJsxOpeningOrSelfClosingElement = isJsxOpeningLikeElement(node);
@@ -33895,6 +33895,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
33895
33895
// If candidate is undefined, it means that no candidates had a suitable arity. In that case,
33896
33896
// skip the checkApplicableSignature check.
33897
33897
if (reportErrors) {
33898
+ if (!headMessage && isCallExpression(node) && isSyntheticHasInstanceMethodCall(node)) {
33899
+ 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;
33900
+ }
33898
33901
if (candidatesForArgumentError) {
33899
33902
if (candidatesForArgumentError.length === 1 || candidatesForArgumentError.length > 3) {
33900
33903
const last = candidatesForArgumentError[candidatesForArgumentError.length - 1];
@@ -33903,7 +33906,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
33903
33906
chain = chainDiagnosticMessages(chain, Diagnostics.The_last_overload_gave_the_following_error);
33904
33907
chain = chainDiagnosticMessages(chain, Diagnostics.No_overload_matches_this_call);
33905
33908
}
33906
- const headMessage = headMessageCallback?.();
33907
33909
if (headMessage) {
33908
33910
chain = chainDiagnosticMessages(chain, headMessage);
33909
33911
}
@@ -33950,7 +33952,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
33950
33952
map(diags, createDiagnosticMessageChainFromDiagnostic),
33951
33953
Diagnostics.No_overload_matches_this_call,
33952
33954
);
33953
- const headMessage = headMessageCallback?.();
33954
33955
if (headMessage) {
33955
33956
chain = chainDiagnosticMessages(chain, headMessage);
33956
33957
}
@@ -33970,18 +33971,18 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
33970
33971
}
33971
33972
}
33972
33973
else if (candidateForArgumentArityError) {
33973
- diagnostics.add(getArgumentArityError(node, [candidateForArgumentArityError], args, headMessageCallback?.() ));
33974
+ diagnostics.add(getArgumentArityError(node, [candidateForArgumentArityError], args, headMessage ));
33974
33975
}
33975
33976
else if (candidateForTypeArgumentError) {
33976
- checkTypeArguments(candidateForTypeArgumentError, (node as CallExpression | TaggedTemplateExpression | JsxOpeningLikeElement).typeArguments!, /*reportErrors*/ true, headMessageCallback?.() );
33977
+ checkTypeArguments(candidateForTypeArgumentError, (node as CallExpression | TaggedTemplateExpression | JsxOpeningLikeElement).typeArguments!, /*reportErrors*/ true, headMessage );
33977
33978
}
33978
33979
else {
33979
33980
const signaturesWithCorrectTypeArgumentArity = filter(signatures, s => hasCorrectTypeArgumentArity(s, typeArguments));
33980
33981
if (signaturesWithCorrectTypeArgumentArity.length === 0) {
33981
- diagnostics.add(getTypeArgumentArityError(node, signatures, typeArguments!, headMessageCallback?.() ));
33982
+ diagnostics.add(getTypeArgumentArityError(node, signatures, typeArguments!, headMessage ));
33982
33983
}
33983
33984
else {
33984
- diagnostics.add(getArgumentArityError(node, signaturesWithCorrectTypeArgumentArity, args, headMessageCallback?.() ));
33985
+ diagnostics.add(getArgumentArityError(node, signaturesWithCorrectTypeArgumentArity, args, headMessage ));
33985
33986
}
33986
33987
}
33987
33988
}
@@ -34334,10 +34335,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
34334
34335
// If the call expression is a synthetic call to a `[Symbol.hasInstance]` method then we will produce a head
34335
34336
// message when reporting diagnostics that explains how we got to `right[Symbol.hasInstance](left)` from
34336
34337
// `left instanceof right`, as it pertains to "Argument" related messages reported for the call.
34337
- return resolveCall(node, callSignatures, candidatesOutArray, checkMode, callChainFlags, () =>
34338
- isSyntheticHasInstanceMethodCall(node) ?
34339
- 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 :
34340
- undefined);
34338
+ return resolveCall(node, callSignatures, candidatesOutArray, checkMode, callChainFlags);
34341
34339
}
34342
34340
34343
34341
function isGenericFunctionReturningFunction(signature: Signature) {
@@ -34718,7 +34716,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
34718
34716
return resolveErrorCall(node);
34719
34717
}
34720
34718
34721
- return resolveCall(node, callSignatures, candidatesOutArray, checkMode, SignatureFlags.None, () => headMessage);
34719
+ return resolveCall(node, callSignatures, candidatesOutArray, checkMode, SignatureFlags.None, headMessage);
34722
34720
}
34723
34721
34724
34722
function createSignatureForJSXIntrinsic(node: JsxOpeningLikeElement, result: Type): Signature {
@@ -37224,7 +37222,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
37224
37222
}
37225
37223
37226
37224
const message = hasGlobalSymbolHasInstanceProperty ?
37227
- 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 :
37225
+ 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 :
37228
37226
Diagnostics.The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type;
37229
37227
error(right, message);
37230
37228
}
@@ -46800,14 +46798,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
46800
46798
if (isBinaryExpression(node.parent)) {
46801
46799
const type = getTypeOfExpression(node.parent.right);
46802
46800
const hasInstanceMethodType = getSymbolHasInstanceMethodOfObjectType(type);
46803
- // const hasInstancePropertyName = getPropertyNameForKnownSymbolName("hasInstance");
46804
- // const hasInstanceProperty = getPropertyOfObjectType(type, hasInstancePropertyName);
46805
- // if (hasInstanceProperty) {
46806
- // const hasInstancePropertyType = getTypeOfSymbol(hasInstanceProperty);
46807
- // if (hasInstancePropertyType && getSignaturesOfType(hasInstancePropertyType, SignatureKind.Call).length !== 0) {
46808
- // return hasInstanceProperty;
46809
- // }
46810
- // }
46811
46801
return hasInstanceMethodType?.symbol ?? type.symbol;
46812
46802
}
46813
46803
return undefined;
0 commit comments