title: How to solve this circular dependency in a factory mode?
body: <p>I need to implement a library in Typescript which follows a simplified factory mode.</p>
  <p>This should be the factory file, <code>lib.ts</code></p>
  <pre><code>import {Options, Product, ProductA} from './product_a';
  import {ProductB,} from './product_b';
  
  export function initialize(options: Options): Product {
    if (/** some condition */) {
      return new ProductA(options);
    } else {
      return new ProductB(options);
    }
  }
  </code></pre>
  <p>First implementation, <code>product_a.ts</code></p>
  <pre><code>export interface Options {
    option1: any;
    option2: any;
  }
  
  export interface Product {
    doTaskAlpha(): void;
    doTaskBeta(): void;
  }
  
  export class ProductA implements Product {
    contructor(options: Options) {}
    /**
     * Implement methons defined in the interface.
     */
  }
  </code></pre>
  <p>Second implementation, <code>product_b.ts</code></p>
  <pre><code>import {Options, Product} from './product_a';
  
  export class ProductB implements Product {
    contructor(options: Options) {}
    /**
     * Implement methons defined in the interface.
     */
  }
  </code></pre>
  <p>As you can see it can be compiled, without circular dependency.</p>
  <p>But the problem happens when the client want to use this library.
  I don't want the client to be able to new their own objects using the certain constructor, instead only through the <code>initialize</code> function defined in <code>lib.ts</code>.</p>
  <p>clients cannot get the interface definition, or the <code>options</code> definition. If I want to expose them in <code>lib.ts</code>, I have to either duplicate the definition in <code>lib.ts</code>, or have a circular dependency.</p>
  <p>I know that this can be achieved by moving the interface <code>Product</code> and <code>Options</code> to a separate file, like <code>opt.ts</code>. But this results in the case that clients have to import two differents files when using this library, which is not perfect.</p>
  <p>How to achieve the goal that only expose the interface, and options definition, without exposing the constructor of the real implementation?</p>