[英]Type '{}' cannot be used as an index type
我正在使用ramda的toPairs
函数。
import { toPairs } from 'ramda';
renderMenuItems({ copy, remove, add, update }) {
return (
toPairs({ copy, remove, add, update })
// make sure we have a function first.
.filter(([, val]) => typeof val === 'function')
.map(([key, value], idx) =>
<MenuItem
key={idx}
icon={ICONS[key]} //Error: Type '{}' cannot be used as an index type
caption={CAPTIONS[key]}
onClick={() => value()}
/>,
)
);
}
key
和value
的类型为{}
。 但是根据docs( http://ramdajs.com/docs/#toPairs ),它是一个字符串。 谁能帮我解决这个问题?
感谢帮助我。
我可以通过设置key
类型和已传递给toPairs
函数的对象的value
来解决此问题。 我在Github文档上找到了@ types.ramda测试用例( https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/ramda/ramda-tests.ts )
这是解决方案。
return (
toPairs<string, number>({ copy, remove, add, update })
...
看起来key
和value
的默认类型均为{}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.