Reputation: 18288
I'm trying to figure out what the proper typings are for the Ramda cookbook method mapKeys
it won't transpile without throwing an error.
Issue
Error is on fn
:
Argument of type '{}' is not assignable to parameter of type '(a: string) => string'. Type '{}' provides no match for the signature '(a: string): string'.
I can see from the typings of R.adjust
that it uses generics, and I tried (a: string) => string
based on the error, which should be the correct typings, and several other variations, such as (a: string) => string[]
.
Can someone indicate what the fn
argument for the anonymous function should be to fix the typings error?
This is really easy to duplicate by just pasting the example into a TypeScript project using VSCode and installing Ramda via npm, and I include the typings for R.adjust
as a 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[];
Upvotes: 0
Views: 430