[英]Why use import and require() in Node.js code?
I am reading the source code at "Type definitions for Express 4.16" and found this funny line (#18):我正在阅读“Express 4.16 的类型定义”中的源代码,并发现了这个有趣的行(#18):
import serveStatic = require("serve-static");
Since import
is the new way to work with modules in ES6, why above code is used or needed at all?既然
import
是 ES6 中处理模块的新方法,为什么要使用或根本需要上面的代码?
Type definitions for Express 4.16 is written(index.d.ts) in typescript, Where import = require()
is a TypeScript Syntax Express 4.16 的类型定义写在 typescript 中(index.d.ts),其中
import = require()
是 TypeScript 语法
TypeScript - Modules (export = and import = require()) TypeScript - 模块(export = 和 import = require())
The export =
syntax specifies a single object that is exported from the module. export =
语法指定从模块导出的单个对象。 This can be a class, interface, namespace, function, or enum.这可以是类、接口、命名空间、函数或枚举。
When exporting a module using export =
, TypeScript-specific import module = require("module")
must be used to import the module .使用
export =
导出模块时,必须使用 TypeScript 特定的import module = require("module")
来导入模块。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.