Bug: __runInitializers(this)
is emitted before super()
call
#53204
Labels
Milestone
__runInitializers(this)
is emitted before super()
call
#53204
Bug Report
🔎 Search Terms
Typescript 5, decorator, emit, __runInitializers, super, constructor
🕗 Version & Regression Information
Version v5.1.0-dev.20230310 (nightly)
v4.9.5
andv5.0.0-rc
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
The emitted output includes the following (abbreviated for clarity; see entire output in playground):
__runInitializers(this, _instanceExtraInitializers);
was emitted before the call tosuper();
in the constructor. This is a problem becausethis
cannot be referenced beforesuper()
is called. The following error is thrown:🙂 Expected behavior
I expect the call to
__runInitializers
to be emitted aftersuper
:🔄 Workaround
Add a private field. Private fields are initialized after
super()
, so the location where__runInitializers
is emitted isn’t a problem.Source:
Output:
(Note/Reminder: Even though the field is written above the constructor, it isn’t executed until after the
super()
call.)The text was updated successfully, but these errors were encountered: