new*_*bie 3 javascript typescript ramda.js
我正在使用 Ramda 的pipe方法。它运行良好,但在第一个参数上给出了一些类型错误flatten。
我不确定它是关于什么的。有人可以解释一下这个问题吗?
代码: https: //stackblitz.com/edit/ramda-playground-vcljpy
错误:
抱歉,标题太幼稚了
谢谢
您需要明确提供类型R.pipe:
const mergeData: any = pipe<
[Data[][]], // arguments supplied to the pipe
Data[], // result of flatten
Data[], // result of filter
Record<string, Data[]>, // result of groupBy
Data[][], // result of values
Data[], // result of map(combine)
RankedData[] // result of last
>(
Run Code Online (Sandbox Code Playgroud)
这适用于以下软件包版本及以上版本:
"@types/ramda": "0.27.34",
"ramda": "0.27.1"
Run Code Online (Sandbox Code Playgroud)
这是工作示例(沙箱)的代码:
interface Data {
name: string;
val: number;
}
interface RankedData extends Data {
rank: string;
}
const ranks = {
a: 'si',
b: 'dp',
d: 'en',
c: 'fr'
};
// merge deep and combine val property values
const combine = mergeWithKey((k, l, r) => (k === 'val' ? l + r : r));
const mergeData: any = pipe<
[Data[][]],
Data[],
Data[],
Record<string, Data[]>,
Data[][],
Data[],
RankedData[]
>(
flatten,
filter((o: Data) => Object.keys(ranks).includes(o.name)),
groupBy(prop('name')), // group by the name
values, // convert back to an array of arrays
map(reduce(combine, {} as Data)), // combine each group to a single object
map((o) => ({
...o,
rank: ranks[o.name]
}))
);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3734 次 |
| 最近记录: |