Broken @lazyInject decorator in TypeScript >=3.7
@lazyInject relies on instrumenting class prototype and prototype bubble mechanism. For now in TS >= 3.7 any of decorators from inversify-inject-decorators don't work
Why worked earliar
@lazyInject*instruments prototype of class with getter and setter for fieldsomething- developer tries to access that property like so:
classInstance.something.doSomething- JS finds no
somethingpropery in current instance - JS find
somethinggetter inclassInstance.__proto__ - JS calls inversify resolver
- ...
- PROFIT!!!
- JS finds no
Current Behavior
@lazyInject*instruments prototype of class with getter and setter for fieldsomething- TS instruments
classInstancewithsomethinggetter on construction - developer tries to access that property like so:
classInstance.something.doSomething- JS finds
somethingpropery getter in current instance - ~~JS find
somethinggetter inclassInstance.__proto__~~ - ~~JS calls inversify resolver~~
- ~~...~~
- ~~PROFIT!!!~~
- JS finds
Possible Solution
For now there are two solutions:
- downgrade to TS 3.6
- use
"useDefineForClassFields": falseintsconfig.json-- set by default
Hm, seems as potential trouble in the future, because TS team wants to use DefineForClassFields compiler strategy as default as I understood.
This is an issue for us as well, because of using mobX with Inversify. MobX 6.x requires the setting of useDefineForClassFields to true (or the Babel equivalent ["@babel/plugin-proposal-class-properties", { "loose": false }]), which breaks lazyInject. Is there any update on this issue?
This is an issue for us as well, because of using mobX with Inversify. MobX 6.x requires the setting of useDefineForClassFields to true (or the Babel equivalent
["@babel/plugin-proposal-class-properties", { "loose": false }]), which breakslazyInject. Is there any update on this issue?
same issue here :(