Bug Report
🔎 Search Terms
class static initializer block esnext useDefineForClassFields
🕗 Version & Regression Information
4.4.1-rc, 4.5.0-dev.20210825
Static Initialization Blocks was newly introduced in TS 4.4.
⏯ Playground Link
Playground
💻 Code
tsconfig.json
{
"compilerOptions": {
"target": "esnext",
"useDefineForClassFields": false
}
}
Code
class A {
static foo = 123;
static {
console.log(this.foo); // should show 123
}
}
🙁 Actual behavior
Following code is emitted. The line marked as // should show 123 would not print 123.
var _a;
class A {
static {
console.log(this.foo); // should show 123
}
}
_a = A;
A.foo = 123;
🙂 Expected behavior
An emit such that execution order of the static field initialization and the static initialization block are kept.
static {} initialization blocks are evaluated in document order interleaved with static field initializers.
ECMAScript class static initialization blocks