Search code examples
typescriptamd

Treat TypeScript modules as Objects


Well, this was working in Typescript 0.8.3 but as they said in "breaking changes" modules can only be used as namespaces.
the javascript implementation of modules is just another object (closure). So, is there any way to have the ability to treat imported modules as objects in TypeScript?

Here is an example:

//Module.ts
export function SomeFunc(){
}

//app.ts
import moduleA = require("Module")
var anotherRef = moduleA;           //this is caught as error!

Using TypeScript 0.8.3 I could pass the anotherRef to any method or even Knockout bindings to use the module reference. but typescript 0.9.x prevents that.

thanks


Solution

  • This works fine for me in TS 0.9.0-1. The limitation you mention is for internal modules and it does not affect external modules (amd/commonjs) like the one you have. i.e. it is only for modules defined with the module keyword as:

    module SomeMod{
        export var foo = 123;  
    }