Skip to content

Commit 6c1d25e

Browse files
committed
add repro test
1 parent a9ae9ee commit 6c1d25e

5 files changed

+155
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
tests/cases/compiler/classVarianceCircularity.ts(13,5): error TS7022: 'Value' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
2+
3+
4+
==== tests/cases/compiler/classVarianceCircularity.ts (1 errors) ====
5+
// Issue #52813
6+
7+
function f() {
8+
const b = new Bar();
9+
// Uncomment to create error
10+
console.log(b.Value);
11+
}
12+
13+
class Bar<T> {
14+
num!: number;
15+
// Or swap these two lines
16+
Field: number = (this as Bar<any>).num;
17+
Value = (this as Bar<any>).num;
18+
~~~~~
19+
!!! error TS7022: 'Value' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
20+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//// [classVarianceCircularity.ts]
2+
// Issue #52813
3+
4+
function f() {
5+
const b = new Bar();
6+
// Uncomment to create error
7+
console.log(b.Value);
8+
}
9+
10+
class Bar<T> {
11+
num!: number;
12+
// Or swap these two lines
13+
Field: number = (this as Bar<any>).num;
14+
Value = (this as Bar<any>).num;
15+
}
16+
17+
//// [classVarianceCircularity.js]
18+
"use strict";
19+
// Issue #52813
20+
function f() {
21+
var b = new Bar();
22+
// Uncomment to create error
23+
console.log(b.Value);
24+
}
25+
var Bar = /** @class */ (function () {
26+
function Bar() {
27+
// Or swap these two lines
28+
this.Field = this.num;
29+
this.Value = this.num;
30+
}
31+
return Bar;
32+
}());
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
=== tests/cases/compiler/classVarianceCircularity.ts ===
2+
// Issue #52813
3+
4+
function f() {
5+
>f : Symbol(f, Decl(classVarianceCircularity.ts, 0, 0))
6+
7+
const b = new Bar();
8+
>b : Symbol(b, Decl(classVarianceCircularity.ts, 3, 9))
9+
>Bar : Symbol(Bar, Decl(classVarianceCircularity.ts, 6, 1))
10+
11+
// Uncomment to create error
12+
console.log(b.Value);
13+
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
14+
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
15+
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
16+
>b.Value : Symbol(Bar.Value, Decl(classVarianceCircularity.ts, 11, 43))
17+
>b : Symbol(b, Decl(classVarianceCircularity.ts, 3, 9))
18+
>Value : Symbol(Bar.Value, Decl(classVarianceCircularity.ts, 11, 43))
19+
}
20+
21+
class Bar<T> {
22+
>Bar : Symbol(Bar, Decl(classVarianceCircularity.ts, 6, 1))
23+
>T : Symbol(T, Decl(classVarianceCircularity.ts, 8, 10))
24+
25+
num!: number;
26+
>num : Symbol(Bar.num, Decl(classVarianceCircularity.ts, 8, 14))
27+
28+
// Or swap these two lines
29+
Field: number = (this as Bar<any>).num;
30+
>Field : Symbol(Bar.Field, Decl(classVarianceCircularity.ts, 9, 17))
31+
>(this as Bar<any>).num : Symbol(Bar.num, Decl(classVarianceCircularity.ts, 8, 14))
32+
>this : Symbol(Bar, Decl(classVarianceCircularity.ts, 6, 1))
33+
>Bar : Symbol(Bar, Decl(classVarianceCircularity.ts, 6, 1))
34+
>num : Symbol(Bar.num, Decl(classVarianceCircularity.ts, 8, 14))
35+
36+
Value = (this as Bar<any>).num;
37+
>Value : Symbol(Bar.Value, Decl(classVarianceCircularity.ts, 11, 43))
38+
>(this as Bar<any>).num : Symbol(Bar.num, Decl(classVarianceCircularity.ts, 8, 14))
39+
>this : Symbol(Bar, Decl(classVarianceCircularity.ts, 6, 1))
40+
>Bar : Symbol(Bar, Decl(classVarianceCircularity.ts, 6, 1))
41+
>num : Symbol(Bar.num, Decl(classVarianceCircularity.ts, 8, 14))
42+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
=== tests/cases/compiler/classVarianceCircularity.ts ===
2+
// Issue #52813
3+
4+
function f() {
5+
>f : () => void
6+
7+
const b = new Bar();
8+
>b : Bar<unknown>
9+
>new Bar() : Bar<unknown>
10+
>Bar : typeof Bar
11+
12+
// Uncomment to create error
13+
console.log(b.Value);
14+
>console.log(b.Value) : void
15+
>console.log : (...data: any[]) => void
16+
>console : Console
17+
>log : (...data: any[]) => void
18+
>b.Value : any
19+
>b : Bar<unknown>
20+
>Value : any
21+
}
22+
23+
class Bar<T> {
24+
>Bar : Bar<T>
25+
26+
num!: number;
27+
>num : number
28+
29+
// Or swap these two lines
30+
Field: number = (this as Bar<any>).num;
31+
>Field : number
32+
>(this as Bar<any>).num : number
33+
>(this as Bar<any>) : Bar<any>
34+
>this as Bar<any> : Bar<any>
35+
>this : this
36+
>num : number
37+
38+
Value = (this as Bar<any>).num;
39+
>Value : any
40+
>(this as Bar<any>).num : number
41+
>(this as Bar<any>) : Bar<any>
42+
>this as Bar<any> : Bar<any>
43+
>this : this
44+
>num : number
45+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// @strict: true
2+
3+
// Issue #52813
4+
5+
function f() {
6+
const b = new Bar();
7+
// Uncomment to create error
8+
console.log(b.Value);
9+
}
10+
11+
class Bar<T> {
12+
num!: number;
13+
// Or swap these two lines
14+
Field: number = (this as Bar<any>).num;
15+
Value = (this as Bar<any>).num;
16+
}

0 commit comments

Comments
 (0)