简体   繁体   English

如何在TypeScript中将导入添加到默认导出

[英]How to add imports to default export in TypeScript

I have this TypeScript node module that imports some base errors ( errors1 and errors2 ) and define some module specific errors3 : 我有这个TypeScript节点模块,该模块导入了一些基本错误( errors1errors2 )并定义了一些模块特定的errors3

// in errors3.ts
import errors1 from './errors1'
import errors2 from './errors2'

const errors3 = {
  ...
}

export default ? // <-- want to merge and export all errors here

Is there a way to combine all 3 error objects into one default export without explicit merging these objects into one manually (ie via Object.assign , lodash , etc? 有没有一种方法可以将所有3个错误对象合并到一个默认导出中,而无需将这些对象明确地手动合并到一个对象中(即通过Object.assignlodash等)?

You can use a barrel to export them all and then import them under a namespace. 您可以使用桶将其全部导出,然后将其导入命名空间下。

https://basarat.gitbooks.io/typescript/docs/tips/barrel.html https://basarat.gitbooks.io/typescript/docs/tips/barrel.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM