I have a module "foo" that I am trying to import into 3 different files (using AMD). Here is my folder structure:
lib/
foo.ts
views/
view1/
view1.ts
view2/
view2.ts
sub/
subview2.ts
I want to be able to setup foo.ts to work for None/AMD/CommonJS. If I put "export = foo;" in the file it won't compile for normal use. I want to be able to set it up as seen below:
module foo {
declare var define: any;
declare var module: any;
if (typeof define === 'function' && define.amd) {
define(() => {
return foo;
});
} else if (typeof module !== 'undefined' && module.exports) {
module.exports = foo;
}
}
declare module 'foo' {
export = foo;
}
The above works for node modules (because of some node magic), but it doesn't work for local files. From the folder structure I have I would need both of the following statements to work.
import foo = require('../../lib/foo');
and
import foo = require('../../../lib/foo');
TypeScript doesn't like me doing either of these, and will complain unless I use the following:
import foo = require('foo');
However this won't work during runtime (unless foo is a packaged node module, which it isn't). I understand I could go into the foo.ts file and put "export = foo;" at the root level, but I didn't write foo, and would rather not edit something I didn't write so that I can easily update it in the future.
Is there a good way around this, or am I missing something?