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 @@ -15546,7 +15546,7 @@ namespace ts {
if (!(isTypeComparableTo(leftType, stringType) || isTypeOfKind(leftType, TypeFlags.NumberLike | TypeFlags.ESSymbol))) {
error(left, Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol);
}
if (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, TypeFlags.Object | TypeFlags.TypeVariable)) {
if (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, TypeFlags.Object | TypeFlags.TypeVariable | TypeFlags.NonPrimitive)) {
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
17 changes: 17 additions & 0 deletions tests/baselines/reference/nonPrimitiveRhsSideOfInExpression.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//// [nonPrimitiveRhsSideOfInExpression.ts]
let o: object = {};

function f(): object {
return {};
}

const b1 = "foo" in o;
const b2 = "bar" in f();

//// [nonPrimitiveRhsSideOfInExpression.js]
var o = {};
function f() {
return {};
}
var b1 = "foo" in o;
var b2 = "bar" in f();
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
=== tests/cases/conformance/types/nonPrimitive/nonPrimitiveRhsSideOfInExpression.ts ===
let o: object = {};
>o : Symbol(o, Decl(nonPrimitiveRhsSideOfInExpression.ts, 0, 3))

function f(): object {
>f : Symbol(f, Decl(nonPrimitiveRhsSideOfInExpression.ts, 0, 19))

return {};
}

const b1 = "foo" in o;
>b1 : Symbol(b1, Decl(nonPrimitiveRhsSideOfInExpression.ts, 6, 5))
>o : Symbol(o, Decl(nonPrimitiveRhsSideOfInExpression.ts, 0, 3))

const b2 = "bar" in f();
>b2 : Symbol(b2, Decl(nonPrimitiveRhsSideOfInExpression.ts, 7, 5))
>f : Symbol(f, Decl(nonPrimitiveRhsSideOfInExpression.ts, 0, 19))

25 changes: 25 additions & 0 deletions tests/baselines/reference/nonPrimitiveRhsSideOfInExpression.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
=== tests/cases/conformance/types/nonPrimitive/nonPrimitiveRhsSideOfInExpression.ts ===
let o: object = {};
>o : object
>{} : {}

function f(): object {
>f : () => object

return {};
>{} : {}
}

const b1 = "foo" in o;
>b1 : boolean
>"foo" in o : boolean
>"foo" : "foo"
>o : object

const b2 = "bar" in f();
>b2 : boolean
>"bar" in f() : boolean
>"bar" : "bar"
>f() : object
>f : () => object

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
let o: object = {};

function f(): object {
return {};
}

const b1 = "foo" in o;
const b2 = "bar" in f();