Setup:
Imagine the following setup:
There is an api that contains let's say a folder foo
and bar
. These folders export all their public stuff to their local index.ts
which will just re-export the public stuff via export * from [...]
to make it more convenient.
In my example, there is a circular dependency, because foo.ts
requires a part of bar
and vice-versa - and I totally understand why this is the case.
See screenshot below:
Question:
How can I resolve this in an environment with hundreds of classes, functions, constants, types, enums, etc. effectively with TypeScript? I imagine that I need some kind of helper file to resolve the commonalities.
Even if I created some kind of foobar
folder that requires foo
and bar
and then exports everything into one big export file it'll probably get messy really soon. What if I need only bar
or only foo
? Is a named export good enough?
I also want to avoid problems in the future, so I am looking for a robust solution. The call precedence is not the main issue that I try to tackle here. It's more about how to set up the dependencies in a smart way.
Goal:
I'd like to use both foo and bar separately and they should be able to share functions/types/enums/interfaces etc. with each other.
A very simple code snippet can be found here: