I have a global variable Module that contains a bunch of constructors for javascript objects. In Javascript I can currently use them like this:

var obj1 = new Module.Class1(1,2,3);
var ob2 = new Module.Class2(»test«)
obj1.method1();
obj2.method2();

I would like to expose those in another namespace NewNamespace, and have strongly typed declarations for methods as well as for constructors. Something like this:

interface  Class1
{
  method1();
}

interface Class2
{
  method2();
}


// TODO: how to define constructors for NewNamespace

let obj2 : Class1= new NewNamespace.Class1(1,2,3);
let obj2 : Class2= new NewNamespace.Class1(1,2,3);
obj1.method1();
obj2.method2();

What is the best way to do this?

0 Answers