Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions tests/baselines/reference/inOperatorWithValidOperands.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ function foo<T>(t: T) {
var rb3 = x in t;
}

function unionCase<T, U>(t: T | U) {
var rb4 = x in t;
}

function unionCase2<T>(t: T | object) {
var rb5 = x in t;
}

interface X { x: number }
interface Y { y: number }

Expand Down Expand Up @@ -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;
Expand Down
58 changes: 42 additions & 16 deletions tests/baselines/reference/inOperatorWithValidOperands.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -59,35 +59,61 @@ function foo<T>(t: T) {
>t : Symbol(t, Decl(inOperatorWithValidOperands.ts, 20, 16))
}

function unionCase<T, U>(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: 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))

22 changes: 22 additions & 0 deletions tests/baselines/reference/inOperatorWithValidOperands.types
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,28 @@ function foo<T>(t: T) {
>t : T
}

function unionCase<T, U>(t: T | U) {
>unionCase : <T, U>(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: T | object) {
>unionCase2 : <T>(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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ function foo<T>(t: T) {
var rb3 = x in t;
}

function unionCase<T, U>(t: T | U) {
var rb4 = x in t;
}

function unionCase2<T>(t: T | object) {
var rb5 = x in t;
}

interface X { x: number }
interface Y { y: number }

Expand Down