Having trouble determining the correct typings for the Ramda cookbook method mapKeys
as it is not transpiling and throwing an error.
Challenge
The issue lies with fn
:
Error message: Argument of type '{}' is not assignable to parameter of type '(a: string) => string'. Type '{}' provides no match for the signature '(a: string): string'.
After examining the typings of R.adjust
, which utilizes generics, I attempted (a: string) => string
in accordance with the error, along with other variations like (a: string) => string[]
.
Could anyone advise on what the proper fn
argument for the anonymous function should be to rectify the typing error?
This issue can easily be replicated by copying the example into a TypeScript project using VSCode and installing Ramda via npm. The typings for R.adjust
are provided for reference.
Example
import * as R from 'ramda';
export const mapKeys = R.curry(
(fn: ???, obj: { [k: string]: any } | { [k: number]: any }) =>
R.fromPairs(
R.map(
R.adjust(fn, 0), // <--- Error: tried typings for `adjust`
R.toPairs(obj)
)
)
);
Ramda Typings for Reference
adjust<T>(fn: (a: T) => T, index: number, list: T[]): T[];
adjust<T>(fn: (a: T) => T, index: number): (list: T[]) => T[];