javascript - 在 TypeScript 中为 'export' 赋值意味着什么?

标签 javascript typescript

declare namespace moment {
...
}

export = moment;

这是从 Moment.js 库的 TypeScript 声明文件中引用的。最后一行是什么意思?这里的'export'关键字和Node.js中的'export'关键字一样吗?

最佳答案

这是 TypeScript 的 'export =' syntax 。来自文档:

The export = syntax specifies a single object that is exported from the module. This can be a class, interface, namespace, function, or enum.

这不是标准的 ES6 JavaScript,如果在那里使用可能会引发语法错误。 TypeScript 转换导出的方式取决于它所处的模式:

Depending on the module target specified during compilation, the compiler will generate appropriate code for Node.js (CommonJS), require.js (AMD), isomorphic (UMD), SystemJS, or ECMAScript 2015 native modules (ES6) module-loading systems. For more information on what the define, require and register calls in the generated code do, consult the documentation for each module loader.

关于javascript - 在 TypeScript 中为 'export' 赋值意味着什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40946908/

相关文章:

javascript - 如何在打字时实时应用验证 [Typescript]

javascript - Html2pf/html2canvas/jsPDF 使用 Bootstrap 模式不显示边框

javascript - 从ajax获取数据同时放入sql查询

javascript - 在 Javascript 中,是否有以下 : variable = variable = value; 的名称

angular - 如何从子组件更改父组件的变量

相当于 elvis “?: return” 运算符的 typescript

javascript - 使用javascript获取元素的子元素

javascript - Angular `watch` 未按预期运行

html - 带文本字段输入的 Angular 2 对话框弹出

typescript - Visual Studio Code 使用 "react-jsx"作为 jsx 值与 create-react-app 的问题