3

when i try to import library in one of external file with namespace typescript can not compile them, how to workaround this?

a.ts

namespace NS {    
    export class A {
        constructor(){

        }
        test(): string {
            return (new B()).callFromA();
        }        
        callFromB(): string {
            return "Call From B";
        }
    }
}

b.ts

namespace NS {    
    export class B {
        constructor(){

        }
        test(): string {
            return (new A()).callFromB();
        }
        callFromA(): string {
            return "Call From A";
        }
    }
}

main.ts

/// <reference path="./libs/a.ts" />
/// <reference path="./libs/b.ts" />
console.log(new NS.A().test());
console.log(new NS.B().test());

output console

tsc --outFile sample.js main.ts libs/a.ts libs/b.ts && node sample.js Call From A Call From B

now if i import a library in one of file,

b.ts

import fs = require(fs);
namespace NS {    
    export class B {
        constructor(){

        }
        test(): string {
            return (new A()).callFromB();
        }
        callFromA(): string {
            return "Call From A";
        }
    }
}

output console

tsc --outFile sample.js main.ts libs/a.ts libs/b.ts && node sample.js libs/a.ts(7,25): error TS2304: Cannot find name 'B'. libs/b.ts(1,1): error TS6131: Cannot compile modules using option 'outFile' unless the '--module' flag is 'amd' or 'system'. libs/b.ts(9,25): error TS2304: Cannot find name 'A'. main.ts(4,20): error TS2339: Property 'B' does not exist on type 'typeof NS'.

DeckyFx
  • 1,308
  • 3
  • 11
  • 32
  • 1
    Possible duplicate https://stackoverflow.com/questions/34714947/how-to-import-two-classes-by-the-same-name-in-javascript-es6 – abdulbarik Jun 08 '17 at 04:28
  • Possible duplicate of [How to import two classes by the same name in javascript/es6?](https://stackoverflow.com/questions/34714947/how-to-import-two-classes-by-the-same-name-in-javascript-es6) – Suraj Rao Jun 08 '17 at 04:58
  • i realize the problem is not lie here but in another spot, i will modify this question – DeckyFx Jun 08 '17 at 05:59

0 Answers0