Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript: Splitting module into multiple files

Tags:

typescript

I want to split class definitions in a same module into multiple files. So I did like this and it worked.

a.ts:
module MyModule{
    class ClassA{
    }
}

b.ts:
module My Module{
    class ClassB{
    }
}

Then I tried to use ClassA in ClassB and did that:

b.ts:
///<reference path="a.ts"/>
module MyModule{
    class ClassB{
        private a:ClassA;
    }
}

But it didn't work; "ClassA" needed to be "MyModule.ClassA" in b.ts though they're in the same module.

I prefer a simpler way like above. Do you have any ideas?

like image 477
uhyoooooo Avatar asked Jan 21 '13 10:01

uhyoooooo


1 Answers

You can solve your problem by making the class public:

module MyModule{
    export class ClassA{
    }
}

I'm not sure why you need to do this as really they are part of the same module - but this seems to be the case.

like image 103
Fenton Avatar answered Sep 20 '22 23:09

Fenton