How to spread module across multiple AMD files?

Topics: General, Language Specification
Oct 8, 2012 at 11:27 PM

I can't figure out if it even possible to have an "export module" spread accross multiple files.

If I have file Contact.ts:

// file Contact.ts
export module Contacts {
   export class Contact {
      ...
   }
}

and another ContactView.ts

// file ContactView.ts
export module Contacts {
   export class ContactView {
      model: Contact;  // <---  is not recognized
   }
}

Then TSC is not recognizing the Contact class. As you can see the Contact and the ContactView are declared to reside in the same module and according to the spec it should work.

I'm building a composite app that uses the require.js and AMD patterns so I HAVE to use the "export module" declaration.

Should I do some type of "ahead declaration" or some tricky "import" ?

Thanks for the advise.

P.S.: This is a cross-post from StackOverflow

Oct 9, 2012 at 7:05 AM

I want to like TypeScript. I really really do. I love strongly typed languages and the ability to have compile time errors.

However, the ability to do this is an absolute requirement for me to adopt TypeScript. I can't have a 5,000+ line code base all in one file. There is no way. It'd be great if I could just have a file which lists all the files that need to be compiled and TypeScript just figures it out and builds one file from them. As far as I can tell, it can't.

Until then, I can't use TypeScript.

I'd love to see this implemented, or if it is, for some clearer documentation on how.

Oct 9, 2012 at 8:52 AM
Edited Oct 9, 2012 at 8:54 AM

Use reference comments instead.

Remove the export keyword from your module definition in Contact.ts and add this line at the top of ContactView.ts:

///<reference path='./Contact.ts' />
Oct 9, 2012 at 6:05 PM

You can also add references with a command line switch.