Skip to content

Commit e5e06d8

Browse files
committed
Allow union types containing primtives as first argument in instanceof
1 parent 7f63180 commit e5e06d8

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6776,7 +6776,7 @@ module ts {
67766776
// and the right operand to be of type Any or a subtype of the 'Function' interface type.
67776777
// The result is always of the Boolean primitive type.
67786778
// NOTE: do not raise error if leftType is unknown as related error was already reported
6779-
if (!isTypeOfKind(leftType, TypeFlags.Any | TypeFlags.ObjectType | TypeFlags.TypeParameter)) {
6779+
if (isTypeOfKind(leftType, TypeFlags.Primitive)) {
67806780
error(node.left, Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter);
67816781
}
67826782
// NOTE: do not raise error if right is unknown as related error was already reported

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,6 +1286,7 @@ module ts {
12861286
Unwidened = 0x00020000, // Unwidened type (is or contains Undefined or Null type)
12871287

12881288
Intrinsic = Any | String | Number | Boolean | Void | Undefined | Null,
1289+
Primitive = String | Number | Boolean | Void | Undefined | Null | StringLiteral | Enum,
12891290
StringLike = String | StringLiteral,
12901291
NumberLike = Number | Enum,
12911292
ObjectType = Class | Interface | Reference | Tuple | Anonymous,

0 commit comments

Comments
 (0)