我如何从'./ foo'`中导出*为foo?

时间:2017-06-02 15:45:27

标签: typescript es6-modules

TypeScript支持re-exports,模块可以导出从另一个模块导入的值:

export {ZipCodeValidator as RegExpBasedZipCodeValidator} from "./ZipCodeValidator";

它还支持通配符导出:

export * from "./StringValidator";

但是,支持此语法(Microsoft/TypeScript#1215讨论语法,它来自ES6并且不包含此表单):

export * as StringValidator from "./StringValidator"

我之所以这样做是因为我可以将我的模块拆分成单独的文件,并使TypeScript等效于这样的声明:

module.exports = {
    foo: require('./foo'),
    bar: require('./bar'),
}

1 个答案:

答案 0 :(得分:0)

感谢Daniel Tabuenca on Gitter

import * as foo from './foo'
import * as bar from './bar'
export {foo, bar}