Open
Description
Bug Report
🔎 Search Terms
class static field super prototype setPrototypeOf
🕗 Version & Regression Information
- The ability to use
super
insidestatic
appears to have been added in 4.4. This bug existed when the feature was introduced, presumably in Change static fields emits #43114.
⏯ Playground Link
Playground link with relevant code
💻 Code
class A {
static x = 1
}
class B extends A {
static y = () => super.x
}
class C {
static x = 2
}
console.log(B.y())
Object.setPrototypeOf(B, C)
console.log(B.y())
🙁 Actual behavior
When this code is transformed by TypeScript, it outputs 1 1
.
🙂 Expected behavior
When this code is run natively, it outputs 1 2
.
The code generated by TypeScript currently looks like this:
"use strict";
var _a, _b;
class A {
}
A.x = 1;
class B extends (_b = A) {
}
_a = B;
B.y = () => Reflect.get(_b, "x", _a);
class C {
}
C.x = 2;
console.log(B.y());
Object.setPrototypeOf(B, C);
console.log(B.y());
I expected something like this instead:
"use strict";
var _a;
class A {
}
A.x = 1;
class B extends A {
}
_a = B;
B.y = () => Reflect.get(Object.getPrototypeOf(_a), "x", _a);
class C {
}
C.x = 2;
console.log(B.y());
Object.setPrototypeOf(B, C);
console.log(B.y());