I have a problem that I think is caused by a circular dependency. After some extensive research, I haven't been able to find a solution. It looks related to this issue : TypeError: b is undefined in __extends in TypeScript, but it didn't help me.
I have been able to simplify the problem in this plunker.
Basically there are 3 classes :
- the class
A, that contains an array ofA - the class
B, that inherits fromA - the class
F, a factory that can create anAor aBdepending on a value
The purpose of this is to handle a parameter list that can be dynamic (each A is a parameter and can be an array) and where B is a specialization of A to handle files. I tried removing the factory, but with only A and B I still get the same error :
TypeError: b is undefined
Error loading http://localhost:3000/app/main.js
Here is the code of a.ts
import { F } from './f';
export class A {
children: A[]
constructor(hasChildren: boolean = false) {
if (hasChildren) {
for (var i = 0 ; i < 10 ; ++i) {
let isB = (Math.random() * 2) > 1;
this.children.push(F.createObject(isB))
}
}
}
}
b.ts
import { A } from './a';
export class B extends A {
}
and f.ts
import { A } from './a'
import { B } from './b'
export class F {
static createObject(isB: boolean): A {
if (isB) {
return new B
} else {
return new A
}
}
}