You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
tests/cases/conformance/classes/members/privateNames/privateNameInInExpression.ts(21,14): error TS2304: Cannot find name '#p1'.
3
-
tests/cases/conformance/classes/members/privateNames/privateNameInInExpression.ts(21,14): error TS18016: Private identifiers are not allowed outside class bodies.
1
+
tests/cases/conformance/classes/members/privateNames/privateNameInInExpression.ts(14,26): error TS2571: Object is of type 'unknown'.
2
+
tests/cases/conformance/classes/members/privateNames/privateNameInInExpression.ts(16,19): error TS18016: Private identifiers are not allowed outside class bodies.
tests/cases/conformance/classes/members/privateNames/privateNameInInExpression.ts(20,14): error TS2304: Cannot find name '#p1'.
5
+
tests/cases/conformance/classes/members/privateNames/privateNameInInExpression.ts(20,14): error TS18016: Private identifiers are not allowed outside class bodies.
6
+
tests/cases/conformance/classes/members/privateNames/privateNameInInExpression.ts(22,23): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter, but here has type 'boolean'.
7
+
tests/cases/conformance/classes/members/privateNames/privateNameInInExpression.ts(34,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
8
+
tests/cases/conformance/classes/members/privateNames/privateNameInInExpression.ts(34,21): error TS2361: The right-hand side of an 'in' expression must not be a primitive.
9
+
tests/cases/conformance/classes/members/privateNames/privateNameInInExpression.ts(36,14): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
10
+
tests/cases/conformance/classes/members/privateNames/privateNameInInExpression.ts(62,12): error TS18016: Private identifiers are not allowed outside class bodies.
#p1 in v; // Bad - RHS of in must be object type or any
19
-
}
20
-
m4(v: any) {
21
-
#p2 in v; // Bad - Invalid private id
22
-
}
23
-
m5(v: any) {
24
-
(#p1) in v; // Bad - private id is not an expression on it's own
25
-
18
+
basics(v: any) {
19
+
const a = #p1 in v; // Good - a is boolean
20
+
21
+
const b = #p1 in v.p1.p2; // Good - b is boolean
22
+
23
+
const c = #p1 in (v as {}); // Good - c is boolean
24
+
25
+
const d = #p1 in (v as Foo); // Good d is boolean (not true)
26
+
27
+
const e = #p1 in (v as unknown); // Bad - RHS of in must be object type or any
28
+
~~~~~~~~~~~~~~
29
+
!!! error TS2571: Object is of type 'unknown'.
30
+
31
+
const f = #p2 in v; // Bad - Invalid privateID
32
+
~~~
33
+
!!! error TS18016: Private identifiers are not allowed outside class bodies.
34
+
35
+
const g = (#p1) in v; // Bad - private id is not an expression on it's own
36
+
26
37
!!! error TS1005: 'in' expected.
27
-
}
28
-
m6(v: any) {
38
+
29
39
for (#p1 in v) { /* no-op */ } // Bad - 'in' not allowed
30
40
~~~
31
41
!!! error TS2304: Cannot find name '#p1'.
32
42
~~~
33
43
!!! error TS18016: Private identifiers are not allowed outside class bodies.
34
-
}
35
-
m7(v: any) {
36
-
for (let x in #p1 in v as any) { /* no-op */ } // Good - weird but valid
37
-
}
38
-
m8(v: any) {
44
+
39
45
for (let x in #p1 in v) { /* no-op */ } // Bad - rhs of in should be a object/any
46
+
~~~~~~~~
47
+
!!! error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter, but here has type 'boolean'.
48
+
49
+
for (let x in #p1 in v as any) { /* no-op */ } // Good - weird but valid
50
+
40
51
}
41
-
m9(v: any) {
52
+
precedence(v: any) {
42
53
// '==' has lower precedence than 'in'
43
54
// '<' has same prededence than 'in'
44
55
// '<<' has higher prededence than 'in'
45
56
46
57
v == #p1 in v == v; // Good precidence: ((v == (#p1 in v)) == v)
47
58
48
59
v << #p1 in v << v; // Good precidence: (v << (#p1 in (v << v)))
60
+
~~~~~~~~~~~~~
61
+
!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
62
+
~~~~~~
63
+
!!! error TS2361: The right-hand side of an 'in' expression must not be a primitive.
49
64
50
65
v << #p1 in v == v; // Good precidence: ((v << (#p1 in v)) == v)
66
+
~~~~~~~~
67
+
!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
51
68
52
69
v == #p1 in v < v; // Good precidence: (v == ((#p1 in v) < v))
53
70
54
71
#p1 in v && #p1 in v; // Good precidence: ((#p1 in v) && (#p1 in v))
55
72
}
56
-
m10() {
57
-
class Bar {
58
-
m10(v: any) {
59
-
#p1 in v; // Good: access parent class
73
+
flow(v: unknown) {
74
+
if (typeof v === 'object' && v !== null) {
75
+
if (#p1 in v) {
76
+
const y1 = v; // good y1 is typeof Foo
77
+
} else {
78
+
const y2 = v; // y2 is not typeof Foo
79
+
}
80
+
}
81
+
82
+
class Nested {
83
+
m(v: any) {
84
+
if (#p1 in v) {
85
+
const y1 = v; // Good y1 if typeof Foo
86
+
}
60
87
}
61
88
}
62
89
}
63
90
}
64
91
65
92
function error(v: Foo) {
66
-
return #p1 in v; // Bad: outside of class
93
+
return #p1 in v; // Bad - outside of class
94
+
~~~
95
+
!!! error TS18016: Private identifiers are not allowed outside class bodies.
0 commit comments