Theo's Typesafe CultTTC
Theo's Typesafe Cult3y ago
2 replies
Ed

Recursive References in TypeScript

I'm stuck with a very specific TS/JS problem, which may not be solvable but I thought I'd see if anyone here has a cool idea on how to solve it.

So I have a file index.ts with a mapping from some keys to objects:
import A from "a.ts";
import B from "b.ts";
...

const mapping = {
    "a": A,
    "b": B,
    ...
};


Then, in the files that contain the objects, they may refer to each other, e.g. in a.ts I may have:
import B from "b.ts";

const A = {
    "something": B;
    ...
}

export default A;


Currently with this setup, I get __WEBPACK_DEFAULT_EXPORT__ and Cannot access 'B' before initialization errors.
Was this page helpful?