在TypeScript中将类导出为Node.js模块 [英] Export class as Node.js module in TypeScript

查看:41
本文介绍了在TypeScript中将类导出为Node.js模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我熟悉TypeScript中的 export 关键字,以及使用TypeScript从Node模块中导出内容的两种规范方法(当然,也可以使用TypeScript模块,但它们甚至可以距离我要找的东西还远):

I'm familiar with the export keyword in TypeScript, and two canonical ways of exporting things from Node modules using TypeScript (of course, the TypeScript modules can be used as well, but they are even further from what I'm looking for):

export class ClassName { }

和一系列

export function functionName () { }

但是,我通常编写模块的方式是:

However, the way I usually write my modules, so that they are later imported as instantiable closures, is:

var ClassName = function () { };
ClassName.prototype.functionName = function () { };
module.exports = ClassName;

有没有办法使用TypeScript导出语法来做到这一点?

Is there a way I can do this using the TypeScript export syntax?

推荐答案

您可以在TypeScript 0.9.0中非常简单地做到这一点:

You can do that quite simply in TypeScript 0.9.0 :

class ClassName { 
    functionName () { }
}

export = ClassName;

这篇关于在TypeScript中将类导出为Node.js模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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