我正在使用ramda的<div class="errorpostcode test">
函数。
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
类型中。但根据文档(http://ramdajs.com/docs/#toPairs),它是一个字符串。
任何人都可以帮我解决这个问题吗?
答案 0 :(得分:0)
感谢帮助我。
我可以通过设置已传递给函数key
的对象的value
和toPairs
类型来解决此问题。我在Github doc上找到了@ types.ramda测试用例(https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/ramda/ramda-tests.ts)
这是解决方案。
return (
toPairs<string, number>({ copy, remove, add, update })
...
对于{}
和key
value