Skip to content

Commit 94afa32

Browse files
authored
Add an extra test case for circular base type (#52071)
1 parent 2082ef2 commit 94afa32

File tree

5 files changed

+66
-1
lines changed

5 files changed

+66
-1
lines changed

tests/baselines/reference/circularBaseTypes.errors.txt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
tests/cases/compiler/circularBaseTypes.ts(4,11): error TS2310: Type 'M2' recursively references itself as a base type.
22
tests/cases/compiler/circularBaseTypes.ts(5,6): error TS2456: Type alias 'M3' circularly references itself.
3+
tests/cases/compiler/circularBaseTypes.ts(13,21): error TS2313: Type parameter 'K' has a circular constraint.
4+
tests/cases/compiler/circularBaseTypes.ts(14,11): error TS2310: Type 'Y' recursively references itself as a base type.
35

46

5-
==== tests/cases/compiler/circularBaseTypes.ts (2 errors) ====
7+
==== tests/cases/compiler/circularBaseTypes.ts (4 errors) ====
68
// Repro from #38098
79

810
type M<T> = { value: T };
@@ -16,4 +18,16 @@ tests/cases/compiler/circularBaseTypes.ts(5,6): error TS2456: Type alias 'M3' ci
1618
function f(m: M3) {
1719
return m.value;
1820
}
21+
22+
// Repro from #32581
23+
24+
type X<T> = { [K in keyof T]: string } & { b: string };
25+
~~~~~~~
26+
!!! error TS2313: Type parameter 'K' has a circular constraint.
27+
!!! related TS2751 tests/cases/compiler/circularBaseTypes.ts:14:11: Circularity originates in type at this location.
28+
interface Y extends X<Y> {
29+
~
30+
!!! error TS2310: Type 'Y' recursively references itself as a base type.
31+
a: "";
32+
}
1933

tests/baselines/reference/circularBaseTypes.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ type M3 = M2[keyof M2]; // Error
88
function f(m: M3) {
99
return m.value;
1010
}
11+
12+
// Repro from #32581
13+
14+
type X<T> = { [K in keyof T]: string } & { b: string };
15+
interface Y extends X<Y> {
16+
a: "";
17+
}
1118

1219

1320
//// [circularBaseTypes.js]
@@ -27,3 +34,11 @@ interface M2 extends M<M3> {
2734
}
2835
type M3 = M2[keyof M2];
2936
declare function f(m: M3): any;
37+
type X<T> = {
38+
[K in keyof T]: string;
39+
} & {
40+
b: string;
41+
};
42+
interface Y extends X<Y> {
43+
a: "";
44+
}

tests/baselines/reference/circularBaseTypes.symbols

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,21 @@ function f(m: M3) {
2626
>m : Symbol(m, Decl(circularBaseTypes.ts, 6, 11))
2727
}
2828

29+
// Repro from #32581
30+
31+
type X<T> = { [K in keyof T]: string } & { b: string };
32+
>X : Symbol(X, Decl(circularBaseTypes.ts, 8, 1))
33+
>T : Symbol(T, Decl(circularBaseTypes.ts, 12, 7))
34+
>K : Symbol(K, Decl(circularBaseTypes.ts, 12, 15))
35+
>T : Symbol(T, Decl(circularBaseTypes.ts, 12, 7))
36+
>b : Symbol(b, Decl(circularBaseTypes.ts, 12, 42))
37+
38+
interface Y extends X<Y> {
39+
>Y : Symbol(Y, Decl(circularBaseTypes.ts, 12, 55))
40+
>X : Symbol(X, Decl(circularBaseTypes.ts, 8, 1))
41+
>Y : Symbol(Y, Decl(circularBaseTypes.ts, 12, 55))
42+
43+
a: "";
44+
>a : Symbol(Y.a, Decl(circularBaseTypes.ts, 13, 26))
45+
}
46+

tests/baselines/reference/circularBaseTypes.types

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,14 @@ function f(m: M3) {
1919
>value : any
2020
}
2121

22+
// Repro from #32581
23+
24+
type X<T> = { [K in keyof T]: string } & { b: string };
25+
>X : X<T>
26+
>b : string
27+
28+
interface Y extends X<Y> {
29+
a: "";
30+
>a : ""
31+
}
32+

tests/cases/compiler/circularBaseTypes.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,10 @@ type M3 = M2[keyof M2]; // Error
1010
function f(m: M3) {
1111
return m.value;
1212
}
13+
14+
// Repro from #32581
15+
16+
type X<T> = { [K in keyof T]: string } & { b: string };
17+
interface Y extends X<Y> {
18+
a: "";
19+
}

0 commit comments

Comments
 (0)