Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential circular dependency issue #422

Closed
jamiewinder opened this issue Apr 24, 2015 · 2 comments
Closed

Potential circular dependency issue #422

jamiewinder opened this issue Apr 24, 2015 · 2 comments
Labels

Comments

@jamiewinder
Copy link

I'm not sure if this should work or not? I have a circular dependency between two modules which doesn't appear to be working. This code is written in TypeScript, and I'm using CommonJS as the output format (I can post the produced JS too, if needed):

mod-a.ts:

import { ClassB } from './mod-b';

export class ClassA
{
  constructor()
  {
  }

  public isB(): boolean
  {
    return this instanceof ClassB;
  }
}

mod-b.ts:

import { ClassA } from './mod-a';

export class ClassB extends ClassA
{
  constructor()
  {
    super();
  }
}

index.ts

import { ClassA } from './mod-a';
import { ClassB } from './mod-b';

var a = new ClassA();
var b = new ClassB();

window.alert(a.isB());
window.alert(b.isB());

The result is an error within the TypeScript-injected __extends function in mod-a.ts where it attempts to set the prototype of the class to that of the base constructor. It's because the base constructor is undefined.

Honestly not sure if this is a problem in TypeScript, in SystemJS, or if it's simply because I'm using the CommonJS output format, and only the register output can handle circular references?

@MajorBreakfast
Copy link
Contributor

Circular dependencies work with the es6 and the register format. CommonJS doesn't support them. Support also cannot be added because of the way CommonJS works.

@jamiewinder
Copy link
Author

I thought that might be it. There is a PR in TypeScript for adding register support, so hopefully that'll do the trick. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants