Skip to content

Potential circular dependency issue #422

Closed

Description

@jamiewinder

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?

Activity

  1. MajorBreakfast commented on Apr 24, 2015

    @MajorBreakfast
    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.

  2. jamiewinder commented on Apr 24, 2015

    @jamiewinder
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions