为什么在 Node.js 代码中使用 import 和 require()?

Why use import and require() in Node.js code?

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

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

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

Type definitions for Express 4.16 是用打字稿写的(index.d.ts),其中 import = require() 是打字稿语法

TypeScript - 模块(导出 = 和导入 = require())

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

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

参考:Modules