Skip to content

Commit 311bb3b

Browse files
committed
Add circularity tests
1 parent ca2768c commit 311bb3b

File tree

3 files changed

+158
-0
lines changed

3 files changed

+158
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts(3,5): error TS2502: 'x' is referenced directly or indirectly in its own type annotation.
2+
tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts(7,5): error TS2502: 'x' is referenced directly or indirectly in its own type annotation.
3+
tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts(15,5): error TS2502: 'x' is referenced directly or indirectly in its own type annotation.
4+
tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts(19,5): error TS2502: 'x' is referenced directly or indirectly in its own type annotation.
5+
tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts(23,5): error TS2502: 'x' is referenced directly or indirectly in its own type annotation.
6+
tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts(27,5): error TS2502: 'x' is referenced directly or indirectly in its own type annotation.
7+
tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts(28,5): error TS2502: 'y' is referenced directly or indirectly in its own type annotation.
8+
tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts(29,5): error TS2502: 'z' is referenced directly or indirectly in its own type annotation.
9+
10+
11+
==== tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts (8 errors) ====
12+
13+
type T1 = {
14+
x: T1["x"]; // Error
15+
~~~~~~~~~~~
16+
!!! error TS2502: 'x' is referenced directly or indirectly in its own type annotation.
17+
};
18+
19+
type T2<K extends "x" | "y"> = {
20+
x: T2<K>[K]; // Error
21+
~~~~~~~~~~~~
22+
!!! error TS2502: 'x' is referenced directly or indirectly in its own type annotation.
23+
y: number;
24+
}
25+
26+
declare let x2: T2<"x">;
27+
let x2x = x2.x;
28+
29+
interface T3<T extends T3<T>> {
30+
x: T["x"]; // Error
31+
~~~~~~~~~~
32+
!!! error TS2502: 'x' is referenced directly or indirectly in its own type annotation.
33+
}
34+
35+
interface T4<T extends T4<T>> {
36+
x: T4<T>["x"]; // Error
37+
~~~~~~~~~~~~~~
38+
!!! error TS2502: 'x' is referenced directly or indirectly in its own type annotation.
39+
}
40+
41+
class C1 {
42+
x: C1["x"]; // Error
43+
~~~~~~~~~~~
44+
!!! error TS2502: 'x' is referenced directly or indirectly in its own type annotation.
45+
}
46+
47+
class C2 {
48+
x: this["y"]; // Error
49+
~~~~~~~~~~~~~
50+
!!! error TS2502: 'x' is referenced directly or indirectly in its own type annotation.
51+
y: this["z"]; // Error
52+
~~~~~~~~~~~~~
53+
!!! error TS2502: 'y' is referenced directly or indirectly in its own type annotation.
54+
z: this["x"]; // Error
55+
~~~~~~~~~~~~~
56+
!!! error TS2502: 'z' is referenced directly or indirectly in its own type annotation.
57+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//// [circularIndexedAccessErrors.ts]
2+
3+
type T1 = {
4+
x: T1["x"]; // Error
5+
};
6+
7+
type T2<K extends "x" | "y"> = {
8+
x: T2<K>[K]; // Error
9+
y: number;
10+
}
11+
12+
declare let x2: T2<"x">;
13+
let x2x = x2.x;
14+
15+
interface T3<T extends T3<T>> {
16+
x: T["x"]; // Error
17+
}
18+
19+
interface T4<T extends T4<T>> {
20+
x: T4<T>["x"]; // Error
21+
}
22+
23+
class C1 {
24+
x: C1["x"]; // Error
25+
}
26+
27+
class C2 {
28+
x: this["y"]; // Error
29+
y: this["z"]; // Error
30+
z: this["x"]; // Error
31+
}
32+
33+
//// [circularIndexedAccessErrors.js]
34+
var x2x = x2.x;
35+
var C1 = (function () {
36+
function C1() {
37+
}
38+
return C1;
39+
}());
40+
var C2 = (function () {
41+
function C2() {
42+
}
43+
return C2;
44+
}());
45+
46+
47+
//// [circularIndexedAccessErrors.d.ts]
48+
declare type T1 = {
49+
x: T1["x"];
50+
};
51+
declare type T2<K extends "x" | "y"> = {
52+
x: T2<K>[K];
53+
y: number;
54+
};
55+
declare let x2: T2<"x">;
56+
declare let x2x: any;
57+
interface T3<T extends T3<T>> {
58+
x: T["x"];
59+
}
60+
interface T4<T extends T4<T>> {
61+
x: T4<T>["x"];
62+
}
63+
declare class C1 {
64+
x: C1["x"];
65+
}
66+
declare class C2 {
67+
x: this["y"];
68+
y: this["z"];
69+
z: this["x"];
70+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// @declaration: true
2+
3+
type T1 = {
4+
x: T1["x"]; // Error
5+
};
6+
7+
type T2<K extends "x" | "y"> = {
8+
x: T2<K>[K]; // Error
9+
y: number;
10+
}
11+
12+
declare let x2: T2<"x">;
13+
let x2x = x2.x;
14+
15+
interface T3<T extends T3<T>> {
16+
x: T["x"]; // Error
17+
}
18+
19+
interface T4<T extends T4<T>> {
20+
x: T4<T>["x"]; // Error
21+
}
22+
23+
class C1 {
24+
x: C1["x"]; // Error
25+
}
26+
27+
class C2 {
28+
x: this["y"]; // Error
29+
y: this["z"]; // Error
30+
z: this["x"]; // Error
31+
}

0 commit comments

Comments
 (0)