Is there a way to access “exports” object in TypeScript modules?

佐手、 提交于 2019-12-10 14:32:06

问题


I am trying to use durandal and I need to getModuleId by passing the current module. My problem is that as I am using TypeScript, the underlaying object which is returned from AMD module seems not to be accessible by Typescript code:

export function checkModule(){
       var a = system.getModuleId(??);
}

the compiled TS will be converted into this:

function checkModule(){
     var a = system.getModule(??);
}
exports.checkModule = checkModule;

instead of ?? I need to pass exports object which is defined in compiled TS. Is there anyway to do that or there is a much simple way? thanks


回答1:


The following is what I use. You are saying "There is an exports variable out there" ... and well there is :)

declare var exports; 
var thisModule = exports; 



回答2:


Well there is one way, to cache the this in the first call to activate method of module:

var _thisModule :any;
export function activate(){
       _thisModule = this;
       ....
}


来源:https://stackoverflow.com/questions/16555506/is-there-a-way-to-access-exports-object-in-typescript-modules

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!