【问题标题】:Why use import and require() in Node.js code?为什么在 Node.js 代码中使用 import 和 require()?
【发布时间】:2019-01-24 03:00:21
【问题描述】:

我正在阅读"Type definitions for Express 4.16" 的源代码,发现这条有趣的线(#18):

import serveStatic = require("serve-static");

既然import 是在 ES6 中使用模块的新方法,为什么要使用或需要上面的代码?

【问题讨论】:

    标签: node.js typescript express ecmascript-6 es6-modules


    【解决方案1】:

    Type definitions for Express 4.16 用 typescript 编写(index.d.ts),其中import = require() 是 TypeScript 语法

    TypeScript - 模块(export = 和 import = require())

    export = 语法指定从模块导出的单个对象。这可以是类、接口、命名空间、函数或枚举。

    使用export = 导出模块时,TypeScript 特定的import module = require("module") 必须用于导入模块

    参考:Modules

    【讨论】:

      猜你喜欢
      • 2022-01-18
      • 1970-01-01
      • 2014-06-26
      • 2018-12-24
      • 2018-08-02
      • 2012-07-18
      • 1970-01-01
      • 2017-07-04
      • 2010-12-23
      相关资源
      最近更新 更多