-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issueRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone
Milestone
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()
}
robpalme, reggi, bananabrann, ExE-Boss, ibrahimxcool and 2 morebananabrann and Radiergummi
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issueRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone