"export = " doesn't work for circular dependencies


If you have circular dependencies where both use "export = ", the compiler will complain:
  • Type reference cannot refer to container '.../A.ts'.
  • Type reference cannot refer to container '.../B.ts'.

import B = require("B");

export = A;

class A {
    public b: B;
import A = require("A");

export = B;

class B {
    public a: A;
If "export class A" and "export class B" is used, it works without problems.

This might not be possible to fix, due to StackOverflow Circular Dependencies AMD
If it actually isn't possible, I'd just like to have it documented.

This issue might be a duplicate of Issue 1263 or at least similar.

file attachments

Closed Aug 1, 2013 at 8:54 PM by paulb
Thanks for reporting. This has recently been fixed in the develop branch.


streetjimmy wrote Aug 31, 2013 at 5:09 PM

I'm still seeing this behaviour (or similar) in TypeScript - paulb, can you say when the relevant fix will appear in a release?

Kyubisation wrote Sep 1, 2013 at 12:24 AM

As far as I can tell, the compiler is now fine with circular dependencies.
That unfortunately doesn't mean AMD (in my case require.js) is fine with it.

From my observations:
classes A, B and C
A references B,
B references both A and C,
C references B

A uses B, no problem.
B uses C, no problem.
If now C wants to use B, it will not work, because in the context of C B is empty.

This might simply be a limitation of AMD, in which case I'd prefer to have it documented somewhere.

PS: If it helps I could create another example project.

paulb wrote Sep 6, 2013 at 10:29 PM

KoenT_IM wrote Aug 30, 2016 at 3:29 PM

I just ran into this problem myself.
After reading this, I'm not sure how to actually solve it though.
I noticed this:
If "export class A" and "export class B" is used, it works without problems.
But how do you deal with situations where you have "nested" classes (in the sense where you have the class and then also a module with the same name, that is)?

I asked this question on SO here (including very simple code + a Bitbucket repo that contains an example project): http://stackoverflow.com/questions/39227992/how-to-solve-issue-with-accessing-static-member-variable-of-nested-class-in-ty

If you have a moment, I'd appreciate it if you had a look at it.