有没有一种方法可以访问“导出” TypeScript模块中的对象? [英] Is there a way to access "exports" object in TypeScript modules?

查看:89
本文介绍了有没有一种方法可以访问“导出” TypeScript模块中的对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用durandal,我需要通过传递 current 模块来 getModuleId 。我的问题是,当我使用TypeScript时,Typescript代码似乎无法访问从AMD模块返回的底层对象:

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(??);
}

已编译的TS将转换为:

the compiled TS will be converted into this:

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

而不是 ?? 在编译的TS中定义的 exports 对象。
是否有这样做或有一种简单的方法?
谢谢

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

推荐答案

以下是我所使用的。您说的是那里有一个出口变量 ...以及::

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; 

这篇关于有没有一种方法可以访问“导出” TypeScript模块中的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆