Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用对象项作为typescript中嵌套对象的索引?_Typescript - Fatal编程技术网

如何使用对象项作为typescript中嵌套对象的索引?

如何使用对象项作为typescript中嵌套对象的索引?,typescript,Typescript,我尝试使用对象项作为嵌套对象的索引,如下所示: type Size='small'|'medium'|'large'; 类型变量='primary'|'secondary'; 常量样式:{ 大小:记录; 变体:记录; } = { 尺寸:{ 小:{padding:8}, 中:{填充:12}, 大:{padding:16}, }, 变体:{ 主:{background:'hotpink'}, 次要:{背景:'银'}, }, }; 常量属性:{size:size;variant:variant}={

我尝试使用对象项作为嵌套对象的索引,如下所示:

type Size='small'|'medium'|'large';
类型变量='primary'|'secondary';
常量样式:{
大小:记录;
变体:记录;
} = {
尺寸:{
小:{padding:8},
中:{填充:12},
大:{padding:16},
},
变体:{
主:{background:'hotpink'},
次要:{背景:'银'},
},
};
常量属性:{size:size;variant:variant}={
尺寸:'中等',
变体:“主要”,
};
constcss=(Object.keys(props)作为数组)。减少(
(附件,钥匙)=>{
常量值=道具[键];
返回{…acc,…style[key][value]};
//^Element隐式具有“any”类型,因为
//“小”|“中”|“大”|“主”|“次”类型的表达式
//无法用于索引类型“记录|记录”
},
{}
);
我使用
作为数组
来避免
对象.keys
只是给出
字符串[]
键——但我不确定接下来如何处理生成的联合类型