mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-11 01:34:55 -06:00
instanceof RHS must be any, callable/constructable or Function subtype
Also includes a fast-path for null and undefined even though they are technically Function subtypes.
This commit is contained in:
parent
7b1fc21460
commit
06b3ea9838
@ -14380,14 +14380,18 @@ namespace ts {
|
||||
}
|
||||
// TypeScript 1.0 spec (April 2014): 4.15.4
|
||||
// The instanceof operator requires the left operand to be of type Any, an object type, or a type parameter type,
|
||||
// and the right operand to be of type Any or a subtype of the 'Function' interface type.
|
||||
// and the right operand to be of type Any, a subtype of the 'Function' interface type, or have a call or construct signature.
|
||||
// The result is always of the Boolean primitive type.
|
||||
// NOTE: do not raise error if leftType is unknown as related error was already reported
|
||||
if (isTypeOfKind(leftType, TypeFlags.Primitive)) {
|
||||
error(left, Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter);
|
||||
}
|
||||
// NOTE: do not raise error if right is unknown as related error was already reported
|
||||
if (!(isTypeAny(rightType) || isTypeSubtypeOf(rightType, globalFunctionType))) {
|
||||
if (!(isTypeAny(rightType) ||
|
||||
rightType.flags & TypeFlags.Nullable ||
|
||||
getSignaturesOfType(rightType, SignatureKind.Call).length ||
|
||||
getSignaturesOfType(rightType, SignatureKind.Construct).length ||
|
||||
isTypeSubtypeOf(rightType, globalFunctionType))) {
|
||||
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);
|
||||
}
|
||||
return booleanType;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user