我已经解决了许多其他有类似错误的问题,但没有看到我的代码有什么问题。你能确定如何修复ts(7053)错误。
我收到的完整错误是
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ card: number; dialog: number; navigation: number; layer: number; blanket: number; modal: number; flag: number; spotlight: number; tooltip: number; }'.
代码是
const zIndexToName: Record<number, string> = Object.keys(layerIndex).reduce(
(acc: Record<number, string>, name: string) => {
const value: number = layerIndex[name]();
acc[value] = name;
return acc;
},
{}
);
鉴于,layerIndex是
export const layerIndex = {
card: 100,
dialog: 300,
navigation: 200,
layer: 400,
blanket: 500,
modal: 510,
flag: 600,
spotlight: 700,
tooltip: 800
};
我可以全部切换string到any但得到相同的错误,Element implicitly has an 'any' type because expression of type 'any' can't be used to index type
const zIndexToName: Record<number, any> = Object.keys(layerIndex).reduce(
(acc: Record<number, any>, name: any) => {
const value: number = layerIndex[name]();
acc[value] = name;
return acc;
},
{}
);
鸿蒙传说
相关分类