类型“{}”不能用作索引类型

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()}
          />,
      )
    );
  }

keyvalue 的类型是 {}。但根据 docs(http://ramdajs.com/docs/#toPairs) 它是一个字符串。 谁能帮我解决这个问题?

感谢您的帮助。

我可以通过设置传递给函数 toPairs 的对象 keyvalue 的类型来解决问题。我在 Github 文档中找到了 @types.ramda 测试用例 (https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/ramda/ramda-tests.ts)

这是解决方案。

 return (
      toPairs<string, number>({ copy, remove, add, update })
      ...

看起来 keyvalue

的默认类型都是 {}