此问题在此处已有答案:
TypeScript- assert type of keys in Object.entries forEach(1个答案)
昨天关门了。
以下内容的正确类型是什么:
type Composition = {
foo: number;
bar: number;
};
const total = 4;
const composition: Composition = { foo: 3, bar: 1 };
for (const [key, value] of Object.entries(composition)) {
composition[key] = (value / total) * 100;
// ^--- Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Composition'.
// ^--- No index signature with a parameter of type 'string' was found on type 'Composition'
}
1条答案
按热度按时间oknwwptz1#
啊找到了!