Closed
Description
TypeScript Version: Nightly Playground
The following code (Playground link) is legal in JavaScript, but produces a static error in TypeScript:
class C {
static a = 'a';
static b = this.a;
// 'this' cannot be referenced in a static property initializer.
}
console.log(C.b); // 'a'
Practical use case – my library Enumify for enums:
class Color extends Enumify {
static red = new Color();
static orange = new Color();
static yellow = new Color();
static green = new Color();
static blue = new Color();
static purple = new Color();
static _ = this.closeEnum(); // TypeScript: Color.closeEnum()
}