我有以下项目结构:
build/
build.ts
config/
config.ts
index.ts
...
config.ts
包含默认的导出类型,如下所示:
export default {
myProp: {
someProp: "someValue"
}
}
index.ts
中的config/
如下所示:
export * from './config';
现在我想在build.ts
中导入配置类型,如下所示:
import config from '../config';
但在使用时(例如config.myProp
),它告诉我myProp
上不存在index.ts
。
根据官方模块文档here,这应该完全正常。我在这里错过了什么吗?
答案 0 :(得分:5)
在config/index.ts
中重新导出配置:
export {default as config} from './config';
然后在build/build.ts
:
import {config} from '../config;
答案 1 :(得分:0)
由于潜在问题的数量,似乎有一种趋势是不使用默认导出。建议使用命名出口。我本人很高兴遵循约定只使用命名的导出。 here所示的原因与我在该主题上的经验相符。
但是,如果您仍然选择默认导出,那么我认为您应该能够像这样在config/index.ts
中重新导出它:
export {default} from './config';
然后在build/build.ts
中,您应该可以进行
import config from '../config';