Node.js 如何在TypeScript中将导入添加到默认导出
我有一个TypeScript节点模块,它导入一些基本错误(Node.js 如何在TypeScript中将导入添加到默认导出,node.js,typescript,Node.js,Typescript,我有一个TypeScript节点模块,它导入一些基本错误(errors1和errors2),并定义一些特定于模块的errors3: // in errors3.ts import errors1 from './errors1' import errors2 from './errors2' const errors3 = { ... } export default ? // <-- want to merge and export all errors here //在err
errors1
和errors2
),并定义一些特定于模块的errors3
:
// in errors3.ts
import errors1 from './errors1'
import errors2 from './errors2'
const errors3 = {
...
}
export default ? // <-- want to merge and export all errors here
//在errors3.ts中
从“./errors1”导入错误1
从“./errors2”导入errors2
常量错误3={
...
}
导出默认值?// 您可以使用一个桶将它们全部导出,然后在名称空间下导入它们
谢谢。是的,我知道这种汇总技术需要创建另一个文件。我想知道是否有一种方法可以保留描述中显示的3个文件。也许这可以在语法层面上解决。不确定,嗯。也许把{errors1,errors2,errors3}导出为allErrors?我想这就是你想要的。看起来我无法从“./errors3”导入错误,并在一个对象中获取所有错误。也许我要求的东西不存在,我需要的唯一方法就是通过export default Object.assign(errors3,errors2,errors1)