Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken @lazyInject decorator in TypeScript >=3.7 #1212

Open
BANOnotIT opened this issue May 3, 2020 · 1 comment
Open

Broken @lazyInject decorator in TypeScript >=3.7 #1212

BANOnotIT opened this issue May 3, 2020 · 1 comment

Comments

@BANOnotIT
Copy link

@BANOnotIT BANOnotIT commented May 3, 2020

@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

  1. @lazyInject* instruments prototype of class with getter and setter for field something
  2. developer tries to access that property like so: classInstance.something.doSomething
    1. JS finds no something propery in current instance
    2. JS find something getter in classInstance.__proto__
    3. JS calls inversify resolver
    4. ...
    5. PROFIT!!!

Current Behavior

  1. @lazyInject* instruments prototype of class with getter and setter for field something
  2. TS instruments classInstance with something getter on construction
  3. developer tries to access that property like so: classInstance.something.doSomething
    1. JS finds something propery getter in current instance
    2. JS find something getter in classInstance.__proto__
    3. JS calls inversify resolver
    4. ...
    5. PROFIT!!!

Possible Solution

For now there are two solutions:

  1. downgrade to TS 3.6
  2. use "useDefineForClassFields": false in tsconfig.json -- set by default
@MirKml
Copy link

@MirKml MirKml commented May 18, 2020

Hm, seems as potential trouble in the future, because TS team wants to use DefineForClassFields compiler strategy as default as I understood.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.