diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 20e6310f77..d110dfcf21 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -22153,7 +22153,7 @@ namespace ts { if (!(isTypeComparableTo(leftType, stringType) || isTypeAssignableToKind(leftType, TypeFlags.NumberLike | TypeFlags.ESSymbolLike))) { error(left, Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol); } - if (!isTypeAssignableToKind(rightType, TypeFlags.NonPrimitive | TypeFlags.InstantiableNonPrimitive)) { + if (!allTypesAssignableToKind(rightType, TypeFlags.NonPrimitive | TypeFlags.InstantiableNonPrimitive)) { error(right, Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } return booleanType; diff --git a/tests/baselines/reference/inOperatorWithValidOperands.js b/tests/baselines/reference/inOperatorWithValidOperands.js index 561abbe340..f01380b35d 100644 --- a/tests/baselines/reference/inOperatorWithValidOperands.js +++ b/tests/baselines/reference/inOperatorWithValidOperands.js @@ -23,6 +23,14 @@ function foo(t: T) { var rb3 = x in t; } +function unionCase(t: T | U) { + var rb4 = x in t; +} + +function unionCase2(t: T | object) { + var rb5 = x in t; +} + interface X { x: number } interface Y { y: number } @@ -53,6 +61,12 @@ var rb2 = x in {}; function foo(t) { var rb3 = x in t; } +function unionCase(t) { + var rb4 = x in t; +} +function unionCase2(t) { + var rb5 = x in t; +} var c1; var c2; var c3; diff --git a/tests/baselines/reference/inOperatorWithValidOperands.symbols b/tests/baselines/reference/inOperatorWithValidOperands.symbols index 75e561989e..cbe0dbeef4 100644 --- a/tests/baselines/reference/inOperatorWithValidOperands.symbols +++ b/tests/baselines/reference/inOperatorWithValidOperands.symbols @@ -59,35 +59,61 @@ function foo(t: T) { >t : Symbol(t, Decl(inOperatorWithValidOperands.ts, 20, 16)) } +function unionCase(t: T | U) { +>unionCase : Symbol(unionCase, Decl(inOperatorWithValidOperands.ts, 22, 1)) +>T : Symbol(T, Decl(inOperatorWithValidOperands.ts, 24, 19)) +>U : Symbol(U, Decl(inOperatorWithValidOperands.ts, 24, 21)) +>t : Symbol(t, Decl(inOperatorWithValidOperands.ts, 24, 25)) +>T : Symbol(T, Decl(inOperatorWithValidOperands.ts, 24, 19)) +>U : Symbol(U, Decl(inOperatorWithValidOperands.ts, 24, 21)) + + var rb4 = x in t; +>rb4 : Symbol(rb4, Decl(inOperatorWithValidOperands.ts, 25, 7)) +>x : Symbol(x, Decl(inOperatorWithValidOperands.ts, 0, 3)) +>t : Symbol(t, Decl(inOperatorWithValidOperands.ts, 24, 25)) +} + +function unionCase2(t: T | object) { +>unionCase2 : Symbol(unionCase2, Decl(inOperatorWithValidOperands.ts, 26, 1)) +>T : Symbol(T, Decl(inOperatorWithValidOperands.ts, 28, 20)) +>t : Symbol(t, Decl(inOperatorWithValidOperands.ts, 28, 23)) +>T : Symbol(T, Decl(inOperatorWithValidOperands.ts, 28, 20)) + + var rb5 = x in t; +>rb5 : Symbol(rb5, Decl(inOperatorWithValidOperands.ts, 29, 7)) +>x : Symbol(x, Decl(inOperatorWithValidOperands.ts, 0, 3)) +>t : Symbol(t, Decl(inOperatorWithValidOperands.ts, 28, 23)) +} + interface X { x: number } ->X : Symbol(X, Decl(inOperatorWithValidOperands.ts, 22, 1)) ->x : Symbol(X.x, Decl(inOperatorWithValidOperands.ts, 24, 13)) +>X : Symbol(X, Decl(inOperatorWithValidOperands.ts, 30, 1)) +>x : Symbol(X.x, Decl(inOperatorWithValidOperands.ts, 32, 13)) interface Y { y: number } ->Y : Symbol(Y, Decl(inOperatorWithValidOperands.ts, 24, 25)) ->y : Symbol(Y.y, Decl(inOperatorWithValidOperands.ts, 25, 13)) +>Y : Symbol(Y, Decl(inOperatorWithValidOperands.ts, 32, 25)) +>y : Symbol(Y.y, Decl(inOperatorWithValidOperands.ts, 33, 13)) var c1: X | Y; ->c1 : Symbol(c1, Decl(inOperatorWithValidOperands.ts, 27, 3)) ->X : Symbol(X, Decl(inOperatorWithValidOperands.ts, 22, 1)) ->Y : Symbol(Y, Decl(inOperatorWithValidOperands.ts, 24, 25)) +>c1 : Symbol(c1, Decl(inOperatorWithValidOperands.ts, 35, 3)) +>X : Symbol(X, Decl(inOperatorWithValidOperands.ts, 30, 1)) +>Y : Symbol(Y, Decl(inOperatorWithValidOperands.ts, 32, 25)) var c2: X; ->c2 : Symbol(c2, Decl(inOperatorWithValidOperands.ts, 28, 3)) ->X : Symbol(X, Decl(inOperatorWithValidOperands.ts, 22, 1)) +>c2 : Symbol(c2, Decl(inOperatorWithValidOperands.ts, 36, 3)) +>X : Symbol(X, Decl(inOperatorWithValidOperands.ts, 30, 1)) var c3: Y; ->c3 : Symbol(c3, Decl(inOperatorWithValidOperands.ts, 29, 3)) ->Y : Symbol(Y, Decl(inOperatorWithValidOperands.ts, 24, 25)) +>c3 : Symbol(c3, Decl(inOperatorWithValidOperands.ts, 37, 3)) +>Y : Symbol(Y, Decl(inOperatorWithValidOperands.ts, 32, 25)) var rc1 = x in c1; ->rc1 : Symbol(rc1, Decl(inOperatorWithValidOperands.ts, 31, 3)) +>rc1 : Symbol(rc1, Decl(inOperatorWithValidOperands.ts, 39, 3)) >x : Symbol(x, Decl(inOperatorWithValidOperands.ts, 0, 3)) ->c1 : Symbol(c1, Decl(inOperatorWithValidOperands.ts, 27, 3)) +>c1 : Symbol(c1, Decl(inOperatorWithValidOperands.ts, 35, 3)) var rc2 = x in (c2 || c3); ->rc2 : Symbol(rc2, Decl(inOperatorWithValidOperands.ts, 32, 3)) +>rc2 : Symbol(rc2, Decl(inOperatorWithValidOperands.ts, 40, 3)) >x : Symbol(x, Decl(inOperatorWithValidOperands.ts, 0, 3)) ->c2 : Symbol(c2, Decl(inOperatorWithValidOperands.ts, 28, 3)) ->c3 : Symbol(c3, Decl(inOperatorWithValidOperands.ts, 29, 3)) +>c2 : Symbol(c2, Decl(inOperatorWithValidOperands.ts, 36, 3)) +>c3 : Symbol(c3, Decl(inOperatorWithValidOperands.ts, 37, 3)) diff --git a/tests/baselines/reference/inOperatorWithValidOperands.types b/tests/baselines/reference/inOperatorWithValidOperands.types index 01d6c78b1f..597454605c 100644 --- a/tests/baselines/reference/inOperatorWithValidOperands.types +++ b/tests/baselines/reference/inOperatorWithValidOperands.types @@ -68,6 +68,28 @@ function foo(t: T) { >t : T } +function unionCase(t: T | U) { +>unionCase : (t: T | U) => void +>t : T | U + + var rb4 = x in t; +>rb4 : boolean +>x in t : boolean +>x : any +>t : T | U +} + +function unionCase2(t: T | object) { +>unionCase2 : (t: object | T) => void +>t : object | T + + var rb5 = x in t; +>rb5 : boolean +>x in t : boolean +>x : any +>t : object | T +} + interface X { x: number } >x : number diff --git a/tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithValidOperands.ts b/tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithValidOperands.ts index a4cdfd00a6..738edca2bc 100644 --- a/tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithValidOperands.ts +++ b/tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithValidOperands.ts @@ -22,6 +22,14 @@ function foo(t: T) { var rb3 = x in t; } +function unionCase(t: T | U) { + var rb4 = x in t; +} + +function unionCase2(t: T | object) { + var rb5 = x in t; +} + interface X { x: number } interface Y { y: number }