Skip to content

Commit befa293

Browse files
committed
Address PR feedback
1 parent 4b0eafc commit befa293

14 files changed

+62
-72
lines changed

src/compiler/checker.ts

+11-21
Original file line numberDiff line numberDiff line change
@@ -33791,7 +33791,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3379133791
return createDiagnosticForNodeArray(getSourceFileOfNode(node), typeArguments, Diagnostics.Expected_0_type_arguments_but_got_1, belowArgCount === -Infinity ? aboveArgCount : belowArgCount, argCount);
3379233792
}
3379333793

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 {
3379533795
const isTaggedTemplate = node.kind === SyntaxKind.TaggedTemplateExpression;
3379633796
const isDecorator = node.kind === SyntaxKind.Decorator;
3379733797
const isJsxOpeningOrSelfClosingElement = isJsxOpeningLikeElement(node);
@@ -33895,6 +33895,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3389533895
// If candidate is undefined, it means that no candidates had a suitable arity. In that case,
3389633896
// skip the checkApplicableSignature check.
3389733897
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+
}
3389833901
if (candidatesForArgumentError) {
3389933902
if (candidatesForArgumentError.length === 1 || candidatesForArgumentError.length > 3) {
3390033903
const last = candidatesForArgumentError[candidatesForArgumentError.length - 1];
@@ -33903,7 +33906,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3390333906
chain = chainDiagnosticMessages(chain, Diagnostics.The_last_overload_gave_the_following_error);
3390433907
chain = chainDiagnosticMessages(chain, Diagnostics.No_overload_matches_this_call);
3390533908
}
33906-
const headMessage = headMessageCallback?.();
3390733909
if (headMessage) {
3390833910
chain = chainDiagnosticMessages(chain, headMessage);
3390933911
}
@@ -33950,7 +33952,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3395033952
map(diags, createDiagnosticMessageChainFromDiagnostic),
3395133953
Diagnostics.No_overload_matches_this_call,
3395233954
);
33953-
const headMessage = headMessageCallback?.();
3395433955
if (headMessage) {
3395533956
chain = chainDiagnosticMessages(chain, headMessage);
3395633957
}
@@ -33970,18 +33971,18 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3397033971
}
3397133972
}
3397233973
else if (candidateForArgumentArityError) {
33973-
diagnostics.add(getArgumentArityError(node, [candidateForArgumentArityError], args, headMessageCallback?.()));
33974+
diagnostics.add(getArgumentArityError(node, [candidateForArgumentArityError], args, headMessage));
3397433975
}
3397533976
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);
3397733978
}
3397833979
else {
3397933980
const signaturesWithCorrectTypeArgumentArity = filter(signatures, s => hasCorrectTypeArgumentArity(s, typeArguments));
3398033981
if (signaturesWithCorrectTypeArgumentArity.length === 0) {
33981-
diagnostics.add(getTypeArgumentArityError(node, signatures, typeArguments!, headMessageCallback?.()));
33982+
diagnostics.add(getTypeArgumentArityError(node, signatures, typeArguments!, headMessage));
3398233983
}
3398333984
else {
33984-
diagnostics.add(getArgumentArityError(node, signaturesWithCorrectTypeArgumentArity, args, headMessageCallback?.()));
33985+
diagnostics.add(getArgumentArityError(node, signaturesWithCorrectTypeArgumentArity, args, headMessage));
3398533986
}
3398633987
}
3398733988
}
@@ -34334,10 +34335,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3433434335
// If the call expression is a synthetic call to a `[Symbol.hasInstance]` method then we will produce a head
3433534336
// message when reporting diagnostics that explains how we got to `right[Symbol.hasInstance](left)` from
3433634337
// `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);
3434134339
}
3434234340

3434334341
function isGenericFunctionReturningFunction(signature: Signature) {
@@ -34718,7 +34716,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3471834716
return resolveErrorCall(node);
3471934717
}
3472034718

34721-
return resolveCall(node, callSignatures, candidatesOutArray, checkMode, SignatureFlags.None, () => headMessage);
34719+
return resolveCall(node, callSignatures, candidatesOutArray, checkMode, SignatureFlags.None, headMessage);
3472234720
}
3472334721

3472434722
function createSignatureForJSXIntrinsic(node: JsxOpeningLikeElement, result: Type): Signature {
@@ -37224,7 +37222,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3722437222
}
3722537223

3722637224
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 :
3722837226
Diagnostics.The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type;
3722937227
error(right, message);
3723037228
}
@@ -46800,14 +46798,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4680046798
if (isBinaryExpression(node.parent)) {
4680146799
const type = getTypeOfExpression(node.parent.right);
4680246800
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-
// }
4681146801
return hasInstanceMethodType?.symbol ?? type.symbol;
4681246802
}
4681346803
return undefined;

src/compiler/diagnosticMessages.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3671,7 +3671,7 @@
36713671
"category": "Error",
36723672
"code": 2856
36733673
},
3674-
"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.": {
3674+
"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.": {
36753675
"category": "Error",
36763676
"code": 2857
36773677
},

0 commit comments

Comments
 (0)