Error TS6202: Project references may not form a circular graph.
My structure: -packages --utils --api
utils/tsconfig.json
...
references: [../api/src]
api/tsconfig.json
...
references: [../utils/src]
I need use utils in api package and use some api in utils
Circular dependencies are usually a hint, that your architecture is not yet sound.
Try one or multiple of the following:
example:
// in api
class A {
constructor(private u: U) {}
fancyMethod() {}
}
// in util
class U {
constructor(private a: A) {}
}
In this setting A from api depends on U from util and vice versa. To resolve this, create an Interface, that describes the required functionality from U's point of view and make it dependant on that:
// in api
class A implements FancyIf{
constructor(private u: U) {}
fancyMethod() {}
}
// in util
interface FancyIf {
fancyMethod(): void;
}
class U {
constructor(private a: Fancy) {}
}
This way, util does not need to depend on api, but it defined, what it needs to operate by providing an interface. The more specific class A from api then implements the interface to state, that it can fulfil the needs of the U class.
Hint: Also think about concepts like dependency injection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With