javascript - 如何从打字稿中的文件导入对象的对象
问题描述
如何从打字稿中的文件导入对象的对象。我知道我可以像import house from 'a/b/c/house'
. 但我可以只导入parent
吗?所以我不需要像这样写代码
house.grandparent.parent.xxx
#filepath: a/b/c/house.ts
const house = {
grandparent: {
parent: {
childa: (text: string) => `s'${text}')`,
childb: 'b',
childc: 'c',
},
},
};
export default house;
解决方案
您可以拆分对象。
// house.ts
export const parent = {
childa: (text: string) => `s'${text}')`,
childb: "b",
childc: "c"
};
export const house = {
grandparent: {
parent: parent
}
};
// some-consumer.ts
import { house, parent } from "./house";
console.log(house);
console.log(parent);
推荐阅读
- javascript - Ngrx 效果并行 http 调用
- r - R中的多元回归模型问题
- arrays - Ionic 5:运行时错误:未定义不是对象
- azure-devops - 如果试用过期,如何将许可证密钥添加到 Azure DevOps
- hibernate - org.hibernate.tool.schema.spi.CommandAcceptanceException:执行 DDL 时出错
- reactjs - 如何创建可跨多个 React 项目使用的私有共享组件库
- xml - xsl 变量导致一个空文档
- javascript - Angular中的cdkOverlay MatDialog不起作用
- lua - 使用 make 和 luarocks 在 lua 中安装 CJSON 失败
- codeigniter - sess_destroy() 的注销会话不起作用