Getting type error when using lodash's curryRight with mapValues

27 Views Asked by At

I am trying to create a curried function of Lodash's mapValues.

const curried = curryRight<{ foo: string }, { foo: boolean }>(mapValues)(value => !!value);

curried({ foo: 'bar' }); // { foo: true }
curried({ foo: '' }); // { foo: false }

The function works but I do not know how to fix the type error:

Argument of type '(value: string) => boolean' is not assignable
to parameter of type '{ foo: string }'. (tsserver 2345)

Here is the type for curryRight.

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: __;
    }

Considering the arity of mapValue, this should be the type that I am dealing with:

<T1, R>(func: (t1: T1) => R, arity?: number): RightCurriedFunction1<T1, R>;

Is there a way to type with out casting?

0

There are 0 best solutions below