TypeScript Decorators and Circular Dependencies

后端 未结 3 472
小蘑菇
小蘑菇 2021-01-06 19:03

Consider the sample of inter-dependent code (below) that makes use of decorators.

Now consider the following workflow (yes, I do want to pass the actual exported cla

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-06 19:37

    Hit the same problem today. I solved it slightly differently, by replacing @Test(Parent) by @Test(() => Parent).

    Instead of tracking the class constructor (Parent) in metadata, I track the thunk that returns the constructor (() => Parent). This delays the evaluation of the Parent imported variable until the thunk is invoked, which does the trick.

提交回复
热议问题