假设我有以下代码:
const results = //some complex datastructure generated by a third party api call
const reducedList = results.map((item) => item.awesome_key)
.map((awesomeKeyList) => awesomeKeyList
.reduce((memo, awesomeKey) => {//stuff},{})))
这段代码就像一个魅力。现在说我决定通过 pluck 将 Ramda 用于第一张地图,如下所示:
import R from Ramda;
R.pluck('awesome_key', results)
.map((awesomeKeyList) => awesomeKeyList
.reduce((memo, awesomeKey) => {},{})))
这将失败:
Property 'reduce' does not exist on type '{}'.
Ramda.pluck 上的类型有:
pluck<T>(p: string|number, list: any[]): T[];
pluck(p: string|number): <T>(list: any[]) => T[];
这些类型会阻止我以这种方式使用 reduce 吗?
示例(简化)结构:
things: [
{
awesome_key: [{
long_name: 'string',
short_name: 'string',
types: {
0: 'string from set',
1?: 'string'
}
}]
other_fields not relevant here
}
]