mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Add regression test
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
//// [classStaticPropertyTypeGuard.ts]
|
||||
|
||||
// Repro from #8923
|
||||
|
||||
class A {
|
||||
private static _a: string | undefined;
|
||||
|
||||
public get a(): string {
|
||||
if (A._a) {
|
||||
return A._a; // is possibly null or undefined.
|
||||
}
|
||||
return A._a = 'helloworld';
|
||||
}
|
||||
}
|
||||
|
||||
//// [classStaticPropertyTypeGuard.js]
|
||||
// Repro from #8923
|
||||
var A = (function () {
|
||||
function A() {
|
||||
}
|
||||
Object.defineProperty(A.prototype, "a", {
|
||||
get: function () {
|
||||
if (A._a) {
|
||||
return A._a; // is possibly null or undefined.
|
||||
}
|
||||
return A._a = 'helloworld';
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
return A;
|
||||
}());
|
||||
@@ -0,0 +1,29 @@
|
||||
=== tests/cases/compiler/classStaticPropertyTypeGuard.ts ===
|
||||
|
||||
// Repro from #8923
|
||||
|
||||
class A {
|
||||
>A : Symbol(A, Decl(classStaticPropertyTypeGuard.ts, 0, 0))
|
||||
|
||||
private static _a: string | undefined;
|
||||
>_a : Symbol(A._a, Decl(classStaticPropertyTypeGuard.ts, 3, 9))
|
||||
|
||||
public get a(): string {
|
||||
>a : Symbol(A.a, Decl(classStaticPropertyTypeGuard.ts, 4, 42))
|
||||
|
||||
if (A._a) {
|
||||
>A._a : Symbol(A._a, Decl(classStaticPropertyTypeGuard.ts, 3, 9))
|
||||
>A : Symbol(A, Decl(classStaticPropertyTypeGuard.ts, 0, 0))
|
||||
>_a : Symbol(A._a, Decl(classStaticPropertyTypeGuard.ts, 3, 9))
|
||||
|
||||
return A._a; // is possibly null or undefined.
|
||||
>A._a : Symbol(A._a, Decl(classStaticPropertyTypeGuard.ts, 3, 9))
|
||||
>A : Symbol(A, Decl(classStaticPropertyTypeGuard.ts, 0, 0))
|
||||
>_a : Symbol(A._a, Decl(classStaticPropertyTypeGuard.ts, 3, 9))
|
||||
}
|
||||
return A._a = 'helloworld';
|
||||
>A._a : Symbol(A._a, Decl(classStaticPropertyTypeGuard.ts, 3, 9))
|
||||
>A : Symbol(A, Decl(classStaticPropertyTypeGuard.ts, 0, 0))
|
||||
>_a : Symbol(A._a, Decl(classStaticPropertyTypeGuard.ts, 3, 9))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
=== tests/cases/compiler/classStaticPropertyTypeGuard.ts ===
|
||||
|
||||
// Repro from #8923
|
||||
|
||||
class A {
|
||||
>A : A
|
||||
|
||||
private static _a: string | undefined;
|
||||
>_a : string | undefined
|
||||
|
||||
public get a(): string {
|
||||
>a : string
|
||||
|
||||
if (A._a) {
|
||||
>A._a : string | undefined
|
||||
>A : typeof A
|
||||
>_a : string | undefined
|
||||
|
||||
return A._a; // is possibly null or undefined.
|
||||
>A._a : string
|
||||
>A : typeof A
|
||||
>_a : string
|
||||
}
|
||||
return A._a = 'helloworld';
|
||||
>A._a = 'helloworld' : string
|
||||
>A._a : string | undefined
|
||||
>A : typeof A
|
||||
>_a : string | undefined
|
||||
>'helloworld' : string
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// @strictNullChecks: true
|
||||
// @target: ES5
|
||||
|
||||
// Repro from #8923
|
||||
|
||||
class A {
|
||||
private static _a: string | undefined;
|
||||
|
||||
public get a(): string {
|
||||
if (A._a) {
|
||||
return A._a; // is possibly null or undefined.
|
||||
}
|
||||
return A._a = 'helloworld';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user