Add tests

This commit is contained in:
Anders Hejlsberg 2017-11-17 09:52:37 -08:00
parent 041d04577e
commit 4141a37ba7

View file

@ -0,0 +1,77 @@
// @strict: true
// @declaration: true
// Properties with non-undefined types require initialization
class C1 {
a: number; // Error
b: number | undefined;
c: number | null; // Error
d?: number;
}
// No strict initialization checks in ambient contexts
declare class C2 {
a: number;
b: number | undefined;
c: number | null;
d?: number;
}
// No strict initialization checks for static members
class C3 {
static a: number;
static b: number | undefined;
static c: number | null;
static d?: number;
}
// Initializer satisfies strict initialization check
class C4 {
a = 0;
b: number = 0;
c: string = "abc";
}
// Assignment in constructor satisfies strict initialization check
class C5 {
a: number;
constructor() {
this.a = 0;
}
}
// All code paths must contain assignment
class C6 {
a: number; // Error
constructor(cond: boolean) {
if (cond) {
return;
}
this.a = 0;
}
}
class C7 {
a: number;
constructor(cond: boolean) {
if (cond) {
this.a = 1;
return;
}
this.a = 0;
}
}
// Properties with string literal names aren't checked
class C8 {
a: number; // Error
"b": number;
0: number;
}