forwardRef
In the following example, Person
is defined before Father
but relies on Father
. In this case, you should use forwardRef
to wrap Father
. Otherwise redi would receive undefined
when tries to figure out dependencies of Person
(and it would throw an error in that case).
import { Self, SkipSelf } from "@wendellhu/redi";
class Person {
constructor(
@Self() @Inject(forwardRef(() => Father)) private readonly father: Father,
@SkipSelf()
@Inject(forwardRef(() => Father))
private readonly grandfather: Father,
) {}
}
class Man extends Person {}
class Father extends Man {
changeDiaper(): void {}
}
💡
This is not related to redi itself but how TypeScript is transpiled into JavaScript.