Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests
  • Loading branch information
ahejlsberg committed Nov 17, 2017
commit 4141a37ba7f00b4e829af4c9dc0e1b5a5913aa47
Original file line number Diff line number Diff line change
@@ -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;
}