提问人:Spencer Carney 提问时间:11/3/2023 最后编辑:Spencer Carney 更新时间:11/3/2023 访问量:16
使用 lodash 的 curryRight 和 mapValues 时出现类型错误
Getting type error when using lodash's curryRight with mapValues
问:
我正在尝试创建 Lodash 的 curried 函数。mapValues
const curried = curryRight<{ foo: string }, { foo: boolean }>(mapValues)(value => !!value);
curried({ foo: 'bar' }); // { foo: true }
curried({ foo: '' }); // { foo: false }
该函数有效,但我不知道如何修复类型错误:
Argument of type '(value: string) => boolean' is not assignable
to parameter of type '{ foo: string }'. (tsserver 2345)
interface CurryRight {
<T1, R>(func: (t1: T1) => R, arity?: number): RightCurriedFunction1<T1, R>;
<T1, T2, R>(func: (t1: T1, t2: T2) => R, arity?: number): RightCurriedFunction2<T1, T2, R>;
<T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3) => R, arity?: number): RightCurriedFunction3<T1, T2, T3, R>;
<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arity?: number): RightCurriedFunction4<T1, T2, T3, T4, R>;
<T1, T2, T3, T4, T5, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4, t5: T5) => R, arity?: number): RightCurriedFunction5<T1, T2, T3, T4, T5, R>;
(func: (...args: any[]) => any, arity?: number): (...args: any[]) => any;
placeholder: __;
}
考虑到 的 arity ,这应该是我正在处理的类型:mapValue
<T1, R>(func: (t1: T1) => R, arity?: number): RightCurriedFunction1<T1, R>;
有没有办法在没有铸造的情况下打字?
答: 暂无答案
评论