我想将已知参数绑定到Ramda的回调中,其余的未指定:
import * as R from "ramda";
type Params = Partial<{
param1: number;
param2: number;
param3: number;
}>;
function getBoundCallback(params: Params) {
const { param1, param2, param3 } = params;
const callback = (p1: number, p2: number, p3: number) => {
// do something
};
return R.curry(callback)(
param1 || R.__,
param2 || R.__,
param3 || R.__
);
}
但是我得到了
TS2769: No overload matches this call.
The last overload gave the following error.
Argument of type 'number | Placeholder' is not assignable to parameter of type 'number'.
Type 'Placeholder' is not assignable to type 'number'
正确的方法是什么?
我唯一想到的解决方案是:
const callback = (
_p1: number | R.Placeholder,
_p2: number | R.Placeholder,
_p3: number | R.Placeholder
) => {
const p1 = _p1 as number;
const p2 = _p2 as number;
const p3 = _p3 as number;
// do something
};
这远非最佳。
正确的方法是什么?
我将"types/npm-ramda#dist"
用于Ramda类型声明。