【问题标题】:Module system in TypescriptTypescript 中的模块系统
【发布时间】:2018-05-06 22:05:02
【问题描述】:

我在 typescript 中有一个这样的模块:

let function test(){
//...
}
export default test;

我想让tsc 编译成这样:

let function test(){
    //...
    }
module.exports = test;

但是,我发现它是这样编译的:

let function test(){
        //...
        }
exports.default = test;

所以我必须像这样要求它:

const test = require('xxx').default;

那么如何解决呢?

【问题讨论】:

  • 尝试-出口=测试; - 导入时 - import test = require("yourmodulename");
  • 当你使用export来暴露你的模块时,为什么不使用import来消费它呢?
  • @betadeveloper 非常感谢,它对我有用。
  • @MaazSyedAdeeb 我想使用 commonjs 模块。

标签: javascript typescript module commonjs


【解决方案1】:

那么如何解决呢?

使用export =

固定代码

let function test(){
//...
}
export = test;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-01-02
    • 2017-04-23
    • 1970-01-01
    • 2014-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多