我使用的是Ramda的pipe方法。它运行良好,但在第一个参数 flatten上给出了一些类型错误。
我不知道这是关于什么的。有人能解释一下这个问题吗?
代码:https://stackblitz.com/edit/ramda-playground-vcljpy
错误:

抱歉标题太幼稚了
谢谢
发布于 2021-01-07 00:18:06
您需要显式地将这些类型提供给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
>(这适用于下列软件包的版本及以上版本:
"@types/ramda": "0.27.34",
"ramda": "0.27.1"这是工作示例(沙盒)的代码:
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]
}))
);https://stackoverflow.com/questions/65603918
复制相似问题