Skip to content

Commit 87ee72b

Browse files
committed
Add regression test
1 parent a5e9071 commit 87ee72b

4 files changed

Lines changed: 107 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//// [classStaticPropertyTypeGuard.ts]
2+
3+
// Repro from #8923
4+
5+
class A {
6+
private static _a: string | undefined;
7+
8+
public get a(): string {
9+
if (A._a) {
10+
return A._a; // is possibly null or undefined.
11+
}
12+
return A._a = 'helloworld';
13+
}
14+
}
15+
16+
//// [classStaticPropertyTypeGuard.js]
17+
// Repro from #8923
18+
var A = (function () {
19+
function A() {
20+
}
21+
Object.defineProperty(A.prototype, "a", {
22+
get: function () {
23+
if (A._a) {
24+
return A._a; // is possibly null or undefined.
25+
}
26+
return A._a = 'helloworld';
27+
},
28+
enumerable: true,
29+
configurable: true
30+
});
31+
return A;
32+
}());
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
=== tests/cases/compiler/classStaticPropertyTypeGuard.ts ===
2+
3+
// Repro from #8923
4+
5+
class A {
6+
>A : Symbol(A, Decl(classStaticPropertyTypeGuard.ts, 0, 0))
7+
8+
private static _a: string | undefined;
9+
>_a : Symbol(A._a, Decl(classStaticPropertyTypeGuard.ts, 3, 9))
10+
11+
public get a(): string {
12+
>a : Symbol(A.a, Decl(classStaticPropertyTypeGuard.ts, 4, 42))
13+
14+
if (A._a) {
15+
>A._a : Symbol(A._a, Decl(classStaticPropertyTypeGuard.ts, 3, 9))
16+
>A : Symbol(A, Decl(classStaticPropertyTypeGuard.ts, 0, 0))
17+
>_a : Symbol(A._a, Decl(classStaticPropertyTypeGuard.ts, 3, 9))
18+
19+
return A._a; // is possibly null or undefined.
20+
>A._a : Symbol(A._a, Decl(classStaticPropertyTypeGuard.ts, 3, 9))
21+
>A : Symbol(A, Decl(classStaticPropertyTypeGuard.ts, 0, 0))
22+
>_a : Symbol(A._a, Decl(classStaticPropertyTypeGuard.ts, 3, 9))
23+
}
24+
return A._a = 'helloworld';
25+
>A._a : Symbol(A._a, Decl(classStaticPropertyTypeGuard.ts, 3, 9))
26+
>A : Symbol(A, Decl(classStaticPropertyTypeGuard.ts, 0, 0))
27+
>_a : Symbol(A._a, Decl(classStaticPropertyTypeGuard.ts, 3, 9))
28+
}
29+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
=== tests/cases/compiler/classStaticPropertyTypeGuard.ts ===
2+
3+
// Repro from #8923
4+
5+
class A {
6+
>A : A
7+
8+
private static _a: string | undefined;
9+
>_a : string | undefined
10+
11+
public get a(): string {
12+
>a : string
13+
14+
if (A._a) {
15+
>A._a : string | undefined
16+
>A : typeof A
17+
>_a : string | undefined
18+
19+
return A._a; // is possibly null or undefined.
20+
>A._a : string
21+
>A : typeof A
22+
>_a : string
23+
}
24+
return A._a = 'helloworld';
25+
>A._a = 'helloworld' : string
26+
>A._a : string | undefined
27+
>A : typeof A
28+
>_a : string | undefined
29+
>'helloworld' : string
30+
}
31+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// @strictNullChecks: true
2+
// @target: ES5
3+
4+
// Repro from #8923
5+
6+
class A {
7+
private static _a: string | undefined;
8+
9+
public get a(): string {
10+
if (A._a) {
11+
return A._a; // is possibly null or undefined.
12+
}
13+
return A._a = 'helloworld';
14+
}
15+
}

0 commit comments

Comments
 (0)