Skip to content

Commit afcf859

Browse files
committed
fix test case failures
1 parent cb430eb commit afcf859

6 files changed

Lines changed: 2 additions & 374 deletions

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30008,7 +30008,7 @@ namespace ts {
3000830008
// If constraint is a union/intersection, ensure no types are primitive.
3000930009
isTypeAssignableToKind(rightType, TypeFlags.UnionOrIntersection) && !allTypesAssignableToKind(rightTypeConstraint, TypeFlags.NonPrimitive | TypeFlags.InstantiableNonPrimitive) ||
3001030010
// Otherwise, ensure that at least one type is not a primitive.
30011-
!maybeTypeOfKind(rightTypeConstraint, TypeFlags.NonPrimitive | TypeFlags.InstantiableNonPrimitive)
30011+
!maybeTypeOfKind(rightTypeConstraint, TypeFlags.NonPrimitive | TypeFlags.InstantiableNonPrimitive | TypeFlags.Object)
3001230012
)
3001330013
) {
3001430014
error(right, Diagnostics.The_right_hand_side_of_an_in_expression_must_not_be_a_primitive);

tests/baselines/reference/controlFlowWithTemplateLiterals.errors.txt

Lines changed: 0 additions & 16 deletions
This file was deleted.

tests/baselines/reference/inKeywordTypeguard.errors.txt

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,32 @@
1-
tests/cases/compiler/inKeywordTypeguard.ts(5,16): error TS2361: The right-hand side of an 'in' expression must not be a primitive.
21
tests/cases/compiler/inKeywordTypeguard.ts(6,11): error TS2339: Property 'b' does not exist on type 'A'.
32
tests/cases/compiler/inKeywordTypeguard.ts(8,11): error TS2339: Property 'a' does not exist on type 'B'.
4-
tests/cases/compiler/inKeywordTypeguard.ts(13,16): error TS2361: The right-hand side of an 'in' expression must not be a primitive.
53
tests/cases/compiler/inKeywordTypeguard.ts(14,11): error TS2339: Property 'b' does not exist on type 'A'.
64
tests/cases/compiler/inKeywordTypeguard.ts(16,11): error TS2339: Property 'a' does not exist on type 'B'.
7-
tests/cases/compiler/inKeywordTypeguard.ts(24,16): error TS2361: The right-hand side of an 'in' expression must not be a primitive.
85
tests/cases/compiler/inKeywordTypeguard.ts(27,11): error TS2339: Property 'b' does not exist on type 'AWithOptionalProp | BWithOptionalProp'.
96
Property 'b' does not exist on type 'AWithOptionalProp'.
10-
tests/cases/compiler/inKeywordTypeguard.ts(40,16): error TS2361: The right-hand side of an 'in' expression must not be a primitive.
117
tests/cases/compiler/inKeywordTypeguard.ts(42,11): error TS2339: Property 'b' does not exist on type 'AWithMethod'.
12-
tests/cases/compiler/inKeywordTypeguard.ts(48,16): error TS2361: The right-hand side of an 'in' expression must not be a primitive.
138
tests/cases/compiler/inKeywordTypeguard.ts(49,11): error TS2339: Property 'a' does not exist on type 'never'.
149
tests/cases/compiler/inKeywordTypeguard.ts(50,11): error TS2339: Property 'b' does not exist on type 'never'.
1510
tests/cases/compiler/inKeywordTypeguard.ts(52,11): error TS2339: Property 'a' does not exist on type 'AWithMethod | BWithMethod'.
1611
Property 'a' does not exist on type 'BWithMethod'.
1712
tests/cases/compiler/inKeywordTypeguard.ts(53,11): error TS2339: Property 'b' does not exist on type 'AWithMethod | BWithMethod'.
1813
Property 'b' does not exist on type 'AWithMethod'.
19-
tests/cases/compiler/inKeywordTypeguard.ts(61,16): error TS2361: The right-hand side of an 'in' expression must not be a primitive.
2014
tests/cases/compiler/inKeywordTypeguard.ts(62,11): error TS2339: Property 'b' does not exist on type 'A | C | D'.
2115
Property 'b' does not exist on type 'A'.
2216
tests/cases/compiler/inKeywordTypeguard.ts(64,11): error TS2339: Property 'a' does not exist on type 'B'.
23-
tests/cases/compiler/inKeywordTypeguard.ts(71,16): error TS2361: The right-hand side of an 'in' expression must not be a primitive.
2417
tests/cases/compiler/inKeywordTypeguard.ts(72,32): error TS2339: Property 'b' does not exist on type 'A'.
2518
tests/cases/compiler/inKeywordTypeguard.ts(74,32): error TS2339: Property 'a' does not exist on type 'B'.
26-
tests/cases/compiler/inKeywordTypeguard.ts(81,20): error TS2361: The right-hand side of an 'in' expression must not be a primitive.
2719
tests/cases/compiler/inKeywordTypeguard.ts(82,39): error TS2339: Property 'b' does not exist on type 'A'.
2820
tests/cases/compiler/inKeywordTypeguard.ts(84,39): error TS2339: Property 'a' does not exist on type 'B'.
29-
tests/cases/compiler/inKeywordTypeguard.ts(92,20): error TS2361: The right-hand side of an 'in' expression must not be a primitive.
3021
tests/cases/compiler/inKeywordTypeguard.ts(94,26): error TS2339: Property 'a' does not exist on type 'never'.
31-
tests/cases/compiler/inKeywordTypeguard.ts(100,16): error TS2361: The right-hand side of an 'in' expression must not be a primitive.
32-
tests/cases/compiler/inKeywordTypeguard.ts(107,27): error TS2361: The right-hand side of an 'in' expression must not be a primitive.
3322

3423

35-
==== tests/cases/compiler/inKeywordTypeguard.ts (28 errors) ====
24+
==== tests/cases/compiler/inKeywordTypeguard.ts (17 errors) ====
3625
class A { a: string; }
3726
class B { b: string; }
3827

3928
function negativeClassesTest(x: A | B) {
4029
if ("a" in x) {
41-
~
42-
!!! error TS2361: The right-hand side of an 'in' expression must not be a primitive.
4330
x.b = "1";
4431
~
4532
!!! error TS2339: Property 'b' does not exist on type 'A'.
@@ -52,8 +39,6 @@ tests/cases/compiler/inKeywordTypeguard.ts(107,27): error TS2361: The right-hand
5239

5340
function positiveClassesTest(x: A | B) {
5441
if ("a" in x) {
55-
~
56-
!!! error TS2361: The right-hand side of an 'in' expression must not be a primitive.
5742
x.b = "1";
5843
~
5944
!!! error TS2339: Property 'b' does not exist on type 'A'.
@@ -69,8 +54,6 @@ tests/cases/compiler/inKeywordTypeguard.ts(107,27): error TS2361: The right-hand
6954

7055
function positiveTestClassesWithOptionalProperties(x: AWithOptionalProp | BWithOptionalProp) {
7156
if ("a" in x) {
72-
~
73-
!!! error TS2361: The right-hand side of an 'in' expression must not be a primitive.
7457
x.a = "1";
7558
} else {
7659
x.b = "1";
@@ -90,8 +73,6 @@ tests/cases/compiler/inKeywordTypeguard.ts(107,27): error TS2361: The right-hand
9073

9174
function negativeTestClassesWithMembers(x: AWithMethod | BWithMethod) {
9275
if ("a" in x) {
93-
~
94-
!!! error TS2361: The right-hand side of an 'in' expression must not be a primitive.
9576
x.a();
9677
x.b();
9778
~
@@ -102,8 +83,6 @@ tests/cases/compiler/inKeywordTypeguard.ts(107,27): error TS2361: The right-hand
10283

10384
function negativeTestClassesWithMemberMissingInBothClasses(x: AWithMethod | BWithMethod) {
10485
if ("c" in x) {
105-
~
106-
!!! error TS2361: The right-hand side of an 'in' expression must not be a primitive.
10786
x.a();
10887
~
10988
!!! error TS2339: Property 'a' does not exist on type 'never'.
@@ -127,8 +106,6 @@ tests/cases/compiler/inKeywordTypeguard.ts(107,27): error TS2361: The right-hand
127106

128107
function negativeMultipleClassesTest(x: A | B | C | D) {
129108
if ("a" in x) {
130-
~
131-
!!! error TS2361: The right-hand side of an 'in' expression must not be a primitive.
132109
x.b = "1";
133110
~
134111
!!! error TS2339: Property 'b' does not exist on type 'A | C | D'.
@@ -144,8 +121,6 @@ tests/cases/compiler/inKeywordTypeguard.ts(107,27): error TS2361: The right-hand
144121

145122
function negativePropTest(x: ClassWithUnionProp) {
146123
if ("a" in x.prop) {
147-
~~~~~~
148-
!!! error TS2361: The right-hand side of an 'in' expression must not be a primitive.
149124
let y: string = x.prop.b;
150125
~
151126
!!! error TS2339: Property 'b' does not exist on type 'A'.
@@ -160,8 +135,6 @@ tests/cases/compiler/inKeywordTypeguard.ts(107,27): error TS2361: The right-hand
160135
protected prop: A | B;
161136
inThis() {
162137
if ("a" in this.prop) {
163-
~~~~~~~~~
164-
!!! error TS2361: The right-hand side of an 'in' expression must not be a primitive.
165138
let z: number = this.prop.b;
166139
~
167140
!!! error TS2339: Property 'b' does not exist on type 'A'.
@@ -177,8 +150,6 @@ tests/cases/compiler/inKeywordTypeguard.ts(107,27): error TS2361: The right-hand
177150
a: string;
178151
inThis() {
179152
if ("a" in this) {
180-
~~~~
181-
!!! error TS2361: The right-hand side of an 'in' expression must not be a primitive.
182153
} else {
183154
let y = this.a;
184155
~
@@ -189,17 +160,13 @@ tests/cases/compiler/inKeywordTypeguard.ts(107,27): error TS2361: The right-hand
189160

190161
function positiveIntersectionTest(x: { a: string } & { b: string }) {
191162
if ("a" in x) {
192-
~
193-
!!! error TS2361: The right-hand side of an 'in' expression must not be a primitive.
194163
let s: string = x.a;
195164
} else {
196165
let n: never = x;
197166
}
198167
}
199168
function negativeIntersectionTest() {
200169
if ("ontouchstart" in window) {
201-
~~~~~~
202-
!!! error TS2361: The right-hand side of an 'in' expression must not be a primitive.
203170
window.ontouchstart
204171
} else {
205172
window.ontouchstart

tests/baselines/reference/inOperatorWithValidOperands.errors.txt

Lines changed: 0 additions & 55 deletions
This file was deleted.

tests/baselines/reference/typeGuardOfFromPropNameInUnionType.errors.txt

Lines changed: 0 additions & 136 deletions
This file was deleted.

0 commit comments

Comments
 (0)