How to import module that does not export anything?

Topics: General
Jan 6, 2013 at 7:07 PM

How can I do the following using import in typescript?


define(['test'], function() {});
something like
import module('test');
Jan 7, 2013 at 9:17 PM

As far as I know, if you import a module and don't use it, the compiler will NOT generate an import statement for it. That is because if you just import a module to access type information defined in that module and don't really use any of the exports, you don't get any runtime overhead. So the following example will not generate a require statement:


import Foo = module("foo");

var b:Foo.SomeType = null;

In your case you cannot even use it, since you didn't define any exports. One way around is to define one "dummy" export like an empty function or variable and call that once. 
I use the NOP() function for that to make it clear that it doesn't do anything. 

// Peter
Jan 8, 2013 at 5:25 AM

That is what I do as well, but I thought there might be a more clever solution to that :) I will issue a feature request ;)