reddy reddy - 11 days ago 7
TypeScript Question

Ambiguity between module name and class name

I have the following situation :

module SomeName {
class SomeName {
}

var namespace = SomeName;
}


I need SomeName to refer to the module but it refers to the class.

The namespace variable is required by some external library over which I have no control. I also need to keep the same name for both the module and the class, and in the real code, moving the variable outside of the module would involve some major refactoring while I feel this might just be a matter of knowing a syntax.

How can I refer to the module instead of the class ?

Answer

you could try saving the module as a reference? something like this maybe:

var myModule = module SomeName {}
myModule {
  class SomeName {

  }
  var namespace = SomeName;
}

or

var myModule = module SomeName {
  class SomeName {

  }
  var namespace = SomeName;
}

now myModule is a reference to the module you created. Probably not the best way to solve it but that's what I would start with. Just be aware of where you are in the scope when saving it so you don't mess with anything else. It's hard to judge your restrictions with only this circumstance available.

Comments