You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using decorators along with design type info, decorating a class that depends on another one implicitly adds a class definition ordering constraint. Not properly ordering those class definitions will result in a runtime crash, and the only way to know this is to know this issue before hand.
🔎 Search Terms
decorator initialization
🕗 Version & Regression Information
typescript 3.9.9 and 4.2.3
This is the behavior in every version I tried, and I reviewed the FAQ for entries about Decorators
// [...]letA=classA{constructor(arg){console.log('constructed A!',arg);}};A=__decorate([someDecorator,// EARLY REFERENCE ISSUE: B is defined below, so the JS runtime will complain about not-initialized refs!__metadata("design:paramtypes",[B])],A);// LATE DEFINITION OF B:classB{}// [...]
🙁 Actual behavior
[ERR]: can't access lexical declaration 'B' before initialization
🙂 Expected behavior
TypeScript to either emit code in the right way, or complain at build time to prevent the runtime issue.
The text was updated successfully, but these errors were encountered:
paul-marechal
changed the title
when decorator emit type information class ordering becomes important
when decorators emit type information class ordering becomes important
May 6, 2021
Bug Report
When using decorators along with design type info, decorating a class that depends on another one implicitly adds a class definition ordering constraint. Not properly ordering those class definitions will result in a runtime crash, and the only way to know this is to know this issue before hand.
🔎 Search Terms
decorator initialization
🕗 Version & Regression Information
typescript 3.9.9 and 4.2.3
⏯ Playground Link
Playground link with relevant code
💻 Code
Relevant generated JavaScript:
🙁 Actual behavior
🙂 Expected behavior
TypeScript to either emit code in the right way, or complain at build time to prevent the runtime issue.
The text was updated successfully, but these errors were encountered: