【发布时间】:2017-06-19 22:05:04
【问题描述】:
查看问题标题。我找到了great reference 的export 形式可用,但我还没有看到我在寻找什么。
是否可以执行以下操作?
// file: constants.js
export const SomeConstant1 = 'yay';
export const SomeConstant2 = 'yayayaya';
// file: index.js
export * as Constants from './constants.js';
即这将在index.js 内提供一个命名导出Constants,其中包含来自constants.js 的所有命名导出。
This answer 似乎表明这在 TypeScript 中是不可能的;纯 JavaScript 也一样吗?
(这个例子有点做作;实际上我试图有一个 prop-types.js 模块,它使用命名导出以供 React 包内部使用,但也导出 PropTypes 下的 prop 类型定义以供外部使用. 为了这个问题,我试图简化。)
【问题讨论】: